We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26113
    • 88 Posts
    I’m building a page which sets a handful of placeholders within a snippet.
    At the very top of the template, a snippet makes a select query and returns the field values as placeholder items.

    http://new.rareoopdvds.com/movie?dvd=46&movie=219


    a section of the snippet...
    $modx->setPlaceHolder('movieTitle', $row['title']);
    $modx->setPlaceHolder('movieId', $row['mid']);
    $modx->setPlaceHolder('movieDescription', $row['description']);
    $modx->setPlaceHolder('movieMpaa', $row['mpaa']);
    $modx->setPlaceHolder('moviePrefix', $row['prefix']);


    If I use the placeholders in a chunk or right in the template, they work just fine.
    However, the data is being displayed depending on which tab is active on the page.

    So here I have another snippet which uses a switch to decide which tab gets loaded.
    [[loadAreaDetails]]

    $area =  $_GET['area'];
    
    switch($area) {
    	case "details":
           echo $modx->getPlaceholder('dvdDescription');
    	echo $modx->getChunk('details');
    }

    The snippet  is called from another template which is called with an httprequest object.
    file = 'details';
    url = "/index.php?id=129&area="+file;


    the {{details}} chunk
    <strong>Description:</strong><br />
    <p>
    [+dvdDescription+]
    </p>
    <p>
    testing
    </p>


    I hope I explained this clearly enough, but my problem is, when the snippet finally gets to load a chunk, the placeholders are not populated any more. How can I maintain their values here? I know its retrieving data because the title & image are form placeholders.

      • 22303 MODX Staff
      • 10,725 Posts
      Placeholders are not unset by the engine, so you must be either running out of parsing iterations, or you have some other plugin or snippet interfering with the placeholders somehow. Do you have PHx enabled by chance?
        • 26113
        • 88 Posts
        If PHx should be listed as a plugin, it doesn’t appear to be installed.

        I am only retrieving a single row, which is producing the correct results.
        How do I install PHx and how will this change things?
        Thanks
        Rich
          • 22303 MODX Staff
          • 10,725 Posts
          No, I was thinking the problem might be related to PHx, because it does some specific things to placeholders when it is installed/enabled.

          But now I’m not sure I understand your issue; specifically, can you better explain this:
          The snippet is called from another template which is called with an httprequest object.

          You can’t set placeholders in one request and expect them to be available in another if you are saying that this other snippet is dynamically loaded via Javascript XMLHttpRequests. You’ll have to execute the original snippet on the Ajax requests to populate those placeholders for it as well; if I’m understanding correctly.

          Another technique might be using $_SESSION vars to "share" the data across requests, but without more info, I don’t want to make too many suggestions.
            • 26113
            • 88 Posts
            The placeholders are set in the main template, which calls the main snippet, prior to any other snippet/ajax calls.

            Where I am having trouble is using those placeholders in chunks and snippets loaded with httprequests on the page.
            So my main snippet [[details]], does a db lookup, and uses $modx->setPlaceholder(’ph’, $row[’value’]) to set each field value.
            Once the page is loaded, there are a series of tabs on the page which if clicked will load content into that area via httprequest.
            The ajax request is for a modx page which executes a snippet, which in turn takes the parameter passed by the request url, and a switch is used to decide what chunk or other data it should display -- which include some of those placeholders set at the very beginning of the template.

            The placeholders work if I place them into the template, or into the [*content*].

            The process does work fine because the snippets are outputting content, but my placeholders are lost somewhere, and i’d rather not repeatedly lookup the same data. So I’m wondering why my placeholders are not global on this page, or why when I try to use them in a snippet they are displaying.

            Again, I hope I explaining this well enough. Let me know if you need code or more information.

            Thank you for your time.
            Rich


              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: sandman at Aug 04, 2007, 01:24 PM

              The process does work fine because the snippets are outputting content, but my placeholders are lost somewhere, and i’d rather not repeatedly lookup the same data. So I’m wondering why my placeholders are not global on this page, or why when I try to use them in a snippet they are displaying.

              Again, this is not possible. Placeholders are set only for the scope of a single request. Everything you need access to in subsequent Ajax requests made from your document, including placeholders, must be set in that request. Every Ajax request is just like a regular request for a MODx document, except that it returns the content to the client for processing into the current page content. But nothing of the original page request is going to be available for those requests, unless you explicitly load those placeholders again.