We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
Subscribe: RSS
  • This is the first time I have used a plug-in, so I fully expect user error to be the cause of this one, but can someone tell me what I am doing wrong?

    My goal is to for the user to be able to switch templates when viewing my site, similar to "zen garden", although not as pretty.

    I have tried to implement sottwell’s TemplateSwitcher plug-in.

    // add template=templatename to the URL

    So I have added to the default index page.

    <a href="[~1~]?template=default">default</a><br />
    <a href="[~1~]?template=scraf01">text only</a>

    scraf01 being the name of a template with no css file.

    Clicking on "text only" gives http://www.scraf.nl/index.php?id=1&refurl=%2Findex.php%3Fid%3D1%3Ftemplate%3Dscraf01&err=1

    If I turn on friendly url’s I get

    • If you don’t have friendly urls on, [~1~] will resolve to "index.php?id=1", so you have to use &template= instead.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • Ok, thanks, fixed that, but still not getting any template changes.

        http://www.scraf.nl ( http://www.scraf.nl/index.php?id=1&template=default )

        • [FIXED] Page was getting cached, so the parser wasn’t looking at the templates. ( thanks to sottwell for looking into it for me )

          Possible fix for this in the pipeline.
          • Here is my templateswitcher code (in german), but I think you can reveal the main idea:

            $sideIid is the id of the current document
            $id is the id of the template

            Please note, that all variables must be defined in both templates.

            $id = $_REQUEST['id'];
            $sideId = $_REQUEST['sideId'];
            if (!isset($id) || empty($id))
            {   echo 'Keine Auswahl getroffen';
            $path = "../../";
            include_once $path . "manager/includes/config.inc.php";
            include_once $path . 'manager/includes/document.parser.class.inc.php';
            include_once $path . "manager/processors/cache_sync.class.processor.php";
            $modx = new DocumentParser();
            $table = $modx->getFullTableName('site_content');
            $temptable = $modx->getFullTableName('site_templates');
            $sql = 'update modx_site_content set template=' . $id;
            $sync = new synccache();
            $sync->setCachepath($path . "assets/cache/");
            if (isset($sideId))
            {   $modx->sendRedirect($path . "index.php?id=" . $sideId);
            $displayName = $modx->db->getValue("select templatename from $temptable where id=$id");
            echo "Menü auf <b>$displayName</b> geändert.<br>"
                 . "<p>Bitte den Zurück-Button benutzen"
                 . "<p><b> gegebenfalls Seite neu laden (Taste F5)</b>";