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

    Does anyone know if its possible to make the Mobile Template Switcher (http://modxcms.com/extras/package/591) use multiple ’mobile specific / targeted’ templates? The current setup allows you to sniff the browser and if a mobile device forces the page content to use a template called ’mobile’ I was wondering if on specific pages you could force this to load a ’mobile_page2’ template and in effect have multiple page templates for mobile? (ideally this would be done by a TV on each page where we can specify the mobile template to use just as you can for the full desktop templates)

    I have worked with Everett99 on getting this version of the plugin working nicely to allow a site to be viewed in either desktop or mobile mode, but this has a hardcoded mobile template which clads every page for mobile delivery - what we are after now is a version which could be adapted from here - http://modxcms.com/extras/package/591 to allow each page to specify its own unique mobile template and not mean all the pages in the mobile view of the site all have the same template...

    Anyone got any ideas???

    Many thanks

    dubbs.
      • 19980 ☆ A M B ☆
      • 275 Posts
      Hello

      Quote from: dubbs at Apr 30, 2010, 10:15 AM

      Hi,

      Does anyone know if its possible to make the Mobile Template Switcher (http://modxcms.com/extras/package/591) use multiple ’mobile specific / targeted’ templates? The current setup allows you to sniff the browser and if a mobile device forces the page content to use a template called ’mobile’ I was wondering if on specific pages you could force this to load a ’mobile_page2’ template and in effect have multiple page templates for mobile? (ideally this would be done by a TV on each page where we can specify the mobile template to use just as you can for the full desktop templates)

      I have worked with Everett99 on getting this version of the plugin working nicely to allow a site to be viewed in either desktop or mobile mode, but this has a hardcoded mobile template which clads every page for mobile delivery - what we are after now is a version which could be adapted from here - http://modxcms.com/extras/package/591 to allow each page to specify its own unique mobile template and not mean all the pages in the mobile view of the site all have the same template...

      Anyone got any ideas???

      Many thanks

      dubbs.

      if a mobile parses already a page with assigned tpl ’mobile’ but you got some pages which might be shown in another way, then may be a simple PHx conditionals can help you. For ex. if(DocID)==3 then {{a needed chunk}} else {default chunk}
      Hope it helps (ping me if I am too far from what you needed and still want assistance)
        modx and ecommerce pro
        • 20413
        • 2,877 Posts
        One approach...
        For your {{my_mobile_template}}

        [[template?option=`[*TemplateOption*]`]]
        So if you have iphone1, iphone2...

        <?php
        $option = isset( $option ) ? $option : 'default'; 
         
        $tpl['iphone1']= <<<TPL
        <html>
        template 1
        </html>
        TPL;
        
        $tpl['iphone2']= <<<TPL
        <html>
        template 2
        </html>
        TPL;
        
        $tpl['default']= <<<TPL
        <html>
        default mobile template
        </html>
        TPL;
        
        print $tpl[$option];
        ?>
        
          @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
          • 8168
          • 1,118 Posts

          if a mobile parses already a page with assigned tpl ’mobile’ but you got some pages which might be shown in another way, then may be a simple PHx conditionals can help you. For ex. if(DocID)==3 then {{a needed chunk}} else {default chunk}
          Hope it helps (ping me if I am too far from what you needed and still want assistance)

          Thanks... but not too sure how this would apply to the code that I already have using the Mobile Template Switcher here.... http://modxcms.com/extras/package/591

          E.g. I would like to still use this http://modxcms.com/extras/package/591 but amend the hardcoded element in the configuration tab of this plugin to allow me to set a TV on each page to be called in dynamically. Does that make sense? So instead of the configuration tab of the plugin (http://modxcms.com/extras/package/591) being Mobile Template="mobile" - which then makes all pages render in the "mobile" template if viewed on a mobile it would be something like Mobile Template="[*MobileTemplateChoice*]" which would read in the relevant TV data for the page MODx is rendering and render it with whatever template name has been selected in the TV on the page when it was created...

          Is this possible?
            • 8168
            • 1,118 Posts
            Thanks Mr Haw - but that would mean I would have to have all my template code in a PHP snippet does’nt it? Would prefer to adapt the Mobile Template Switcher code here http://modxcms.com/extras/package/591 rather than create a new system here... Just put in some more detail in the comment above - let me know if this does not make sense! A tricky one to explain.


            Cheers,

            dubbs.
              • 20413
              • 2,877 Posts
              You could use chunks.

              1. Use the plugin
              2. In your MODx template:
              <mobile>
              [!template?option=`[*TemplateOption*]`!]
              </mobile>

              3. Snippet code:
              <?php
              $option  = isset( $option ) ? $option  : 'default'; 
              $tpl['iphone1']= $modx->getChunk("iphone1");
              $tpl['iphone2']= $modx->getChunk("iphone2");
              $tpl['default']= $modx->getChunk("default");
              print $tpl[$option];
              ?>


              I haven’t tested this at all. It might work! wink
                @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
                • 8168
                • 1,118 Posts
                Thanks Mr Haw - I still don’t really understand how to implement that... Will have a play and see if I can figure it out...

                Where would this code go?

                <mobile>
                [!template?option=`[*TemplateOption*]`!]
                </mobile>



                Cheers

                dubbs.

                P.S. Email me if its easier - [email protected] ;] // thanks buddy
                  • 20413
                  • 2,877 Posts
                  The plugin description gives this example:
                  <mobile>
                  	<body class="narrow">
                  </mobile>	
                  <standard>
                  	<body class="huge">
                  </standard>
                  

                  Are you not using these tags?

                  To make it more clear...
                  [*TemplateOptions*] could have following input options:
                  iphone1==1||iphone2==2||default==3

                  The use snippet like this
                  <?php
                  $option  = isset( $option ) ? $option  : '3'; 
                  $tpl['1']= $modx->getChunk("iphone1ChunkName");
                  $tpl['2']= $modx->getChunk("iphone2ChunkName");
                  $tpl['3']= $modx->getChunk("defaultChunkName");
                  print $tpl[$option];
                  ?>

                  Now choosing 1 will go get iphone1ChunkName chunk insde the <mobile> tags (if it works).

                  //Yes the snippet is NOT needed, a TV can do: iphone1=={{chunk}}||iphone2=={{... and store default value.
                    @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
                    • 8168
                    • 1,118 Posts
                    Ahh ok I see where you are coming from here... The normal, desktop and mobile are parameters to allow one to override the ’auto’ detection the script (plugin) sniffs the device to be (eg. mobile or desktop), so not sure how your suggestion would affect this... Will have a play and let you know how I get on.

                    As I said in an earlier thread the ideal would be to leave the plugin as it is and just change the hard-coded Mobile Template="mobile" paramater to read a dynamic value from a Template Variable so in essence make it read Mobile Template="{*MobileTemplateTV*]" but this does not work....

                    Is it possible to pass anything into a plugin configuration setting? Template Variables do not seem to work... :[
                      • 19980 ☆ A M B ☆
                      • 275 Posts
                      Quote from: dubbs at May 03, 2010, 10:01 AM

                      As I said in an earlier thread the ideal would be to leave the plugin as it is and just change the hard-coded Mobile Template="mobile" paramater to read a dynamic value from a Template Variable so in essence make it read Mobile Template="{*MobileTemplateTV*]" but this does not work....

                      Is it possible to pass anything into a plugin configuration setting? Template Variables do not seem to work... :[

                      Hi
                      I have installed this plugin and it works OnPagePrerender...
                      It means to me that page’s content with different code calls (chunk, snippet..) is not parsed before the plugin finished working.

                      Still Not sure what you need but if you want for Iphone to show IPhone section as an index page for exammple but for Opera brouser used by Nokia a Nokia section then u might need to use a redirection snippet

                      So on page load, your plugin will work OnPagePrerender and will put a browser type into $cockie array for Variable $x.
                      Your snippet can read that $x value by standart php methods and have a redictions as a case function.

                      Hope my invented example can unswer your task
                      Cheers
                        modx and ecommerce pro