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

    When rendering a dynamic celebrity page (http://famous-relationships.topsynergy.com/Angelina_Jolie/"" target="_blank" rel="nofollow">see existing example), the celebrity’s basic information is retrieved from a database table and used dozens of times on each and every page that belongs to that celebrity.

    Sample repetitive data segments: uniqueID, name, gender, birth date, photo, and URL string (for file names and URLs).

    Sample use: meta-tags, document content, parsing and manipulating database query results, forms, PHP scripts, and structuring URLs and anchor text in navigation links.

    So I wrote a snippet that retrieves all these data segments for current celebrity (based on friendly URL) and discovered how easy it is to embed the values where needed in the document via:

    1. Conditional output:
    [[getCelebParams? &CelebID=`1` &ParamName=`FullName`]]
    or;

    2. Sending the output to a chunk from within the snippet:
    $output.=$modx->parseChunk('CelebParams', $params, '[+', '+]');


    My challenges are three:

    1. None of this methods works in the template itself. It seems that the snippet’s variables are private and hidden to the template layer. Let’s say that I want to declare a "keywords" meta-tag with the celebrity FullName as the first keyword. How do I call for the value to be parsed in the template before it renders? I tried to play with different @Binding methods to call the snippet via TVs but failed miserably.

    2. If I output each data segment via its dedicated chunk (Name, Date of Birth, He/She, Have/Had, etc.) according to what needs to be parsed in the content, I need to maintain many small and cumbersome chunks. However, if i call the snippet each time, I cause it to re-query the database and re-evaluate the PHP code for no particular need or reason.

    3. To add some complexity - each celebrity will have on the new platform around 40 pages - all share these basic data segments. I believe that being able to cache this data once retrieved for a specific CelebID becomes almost mandatory.

    In summary: can you help me please to see the big picture and to devise the right method to serve all the issues above?
      Cheers,
      Shlomo Tommer
      • 27072
      • 76 Posts
      Thanks a lot, ganeshXL. You’ve made my day.

      So, if I understand correctly - by using the setPlaceholder function, you declare/initialize these placeholders as public variables?

      Quote from: ganeshXL at Feb 18, 2009, 11:53 AM

      Not sure I understand you correctly, but you could add a few placeholder definitions inside of your existing snippet(s), e.g.

      [[getCelebParams? &CelebID=`1` &ParamName=`FullName`]]


      in this snippet, you would add something like

      $modx->setPlaceholder('fullName', '$fullName');


      In your template (or template-chunk), you could use the [+fullName+] placeholder wherever you want: the document title, the meta keywords and description fields, etc.

      Actually, if you pull the infos from a DB, you could create the entire meta-field as one placeholder (i.e. not just name):
      <meta name="description" content="[+metaDescription+]" />


      The trick is simply to call the snippet before using those custom placeholders in your template.
        Cheers,
        Shlomo Tommer
        • 27072
        • 76 Posts
          Cheers,
          Shlomo Tommer