We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42701
    • 47 Posts
    Hi,

    So I'm trying to output a lengthy chunk of HTML code if the browser width is 590px or less (mobile view). I have a simple javascript function that determines the screen's width on resize, but how do I output a chunk if that function returns true?

    The way I'm envisioning it is to have the function inside it's own chunk, but I can't get the chunk to return anything to any output filters, e.g. [[$isMobile:eq=`true`:then=`[[$MobileChunk]]`]]

    Thanks
      • 20413
      • 2,877 Posts
      PHP Snippets are server side and JavaScript/CSS is client side. Any MODX snippet will already be parsed and giving you output before screen re-sizing etc happens.

      That being said JavaScript can import, redirect or load additional code on browser events.

      if (screen.width > 1400) {
           $('#wrapper').load('/map/map4.php');
      } else {
           $('#wrapper').load('/map/map1.php');
      }


      Frameworks like Bootstrap have CSS classes like "hidden-xs" that can be used to change what's being displayed on different screen sizes.
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower