We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44231
    • 126 Posts
    hi there

    I know there's a similar thread about this but there is not clear instructions on how to obtain it.

    Scenario:

    I have a page which contains different products when a user click on a product I want to the name of the product also become my page title? I use snippet and xPDO query because the product details is coming from the custom tables how should I do this??

    This question has been answered by BobRay. See the first response.

      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Perhaps you're overthinking this... if you're using a page as the launchpad to lookup a product, then why not have the Snippet determine everything? E.g. the page containing the snippet could use NO template at all, and the Snippet could load up all the data from the product, and then use a Chunk to format the entire HTML output...

      There are probably many ways you could solve this, but that's one idea.
      • discuss.answer
        • 3749
        • 24,544 Posts
        I agree with Everett, though I think you'd still want a template. Just don't put the [[*pagetitle]] tag in the template (or any other standard resource tags).

        Use custom placeholders and set their values in the snippet:

        [[+MyPlaceholder]]


        $modx->setPlaceholder('MyPlaceholder', 'Some Value');



        If the product table is set up for xPDO, you can also put the Product HTML with its placeholders in a Tpl chunk and do something like this:

        $productData = $modx->getObject('modProduct', $criteria);
        
        if ($productData) {
            $fields = $product->toArray();
            return $modx->getChunk('ProductTplChunk', $fields);
        }


        That will return the chunk, with all the placeholders replaced by values from the table row.

          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          I believe if you set a placeholder in the content (and only the content; doesn't work from other fields) you can reference that throughout the template. It's kind of an exception to how things are parsed normally (top to bottom) but quite convenient for cases like this smiley

          So in your snippet that loads the specific product, use $modx->setPlaceholder() to set some sort of title you reference elsewhere in the template.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.