We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24495
    • 407 Posts
    Would be nice to get a solution for a full-functional preview with all unpublished pages to see documents within context.
      • 3749
      • 24,544 Posts
      You could create an array of documents by calling $modx->getDocument() with all possible document IDs and the appropriate criteria. If getDocument() returns something other than false, add the document object to the array.

      Then you could do whatever you want with that array.

        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
        • 24495
        • 407 Posts
        Better it would be a preview option in MODx. I think it could be a good addition for developers and content editors to see what they do without publishing the documents (e.g. press releases and of course for new created sections in a web site).
          • 3749
          • 24,544 Posts
          Quote from: rasc at Oct 19, 2008, 01:11 PM

          Better it would be a preview option in MODx. I think it could be a good addition for developers and content editors to see what they do without publishing the documents (e.g. press releases and of course for new created sections in a web site).

          You do know that MODx has a preview funtion that will show you any page, right? wink

          You can either right-click on the page in the tree and select "preview" or you can click on the "preview" tab when creating/editing the document.
            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
            • 24495
            • 407 Posts
            @BobRay: the preview function isn’t good because it doesn’t work for me with complex documents containing snippets to read TVs!
            Example: often I asked for solutions regarding the site www.koegel-touristik.de (small german travel business). Each travel page contains of:
            - the content area containing the travel description from first to last day only
            - many TVs for prices, travel type (bus, flight, ...), teaser image, additional information, specifications, ...
            - sub-documents for each travel date containing TVs for start and end date and for stations to get the bus

            Most of TVs are displayed by snippets because of many dependencies. Example for prices: I have for prices some TVs.
            - price for a double room per night
            - additional charge for single room
            - there are partner campains: the first passenger pays a reduced amount, the second the price for double room (first TV value above )
            - some travel have no additional charge using a single room

            Price will be displayed by snippet calculating all dependencies.

            In preview mode of unpublished document I never see the calculated prices, the travel type, the teaser image (displayed by snippet checking wether image is available and having an alt text or using the pagetitle as the alt attribute) and so on.

            THIS preview is unusable for me and my client. And I don’t see an alterative solution.
              • 3749
              • 24,544 Posts
              I see what you’re saying now. I’ve never seen that happen with preview in the Manager. Maybe someone else can comment on why it’s happening for you and if there’s anything you can do to correct it. If it’s uncorrectable, I’d agree that it would be a high priority to have "preview" in the manager produce an accurate preview.

              In the interim, you can always have the page you’re working on visible in another browser looking at the front end and reload it to see changes while you work. Be sure to set "clear cache" in the page settings so you’ll be looking at a fresh page when you reload.
                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
                • 7231
                • 4,205 Posts
                How are you getting/manipulating the data from the TVs? This is just a database call and being published is only a parameter (unless you need to parse something), you should be able to do whatever youwant to the data regardless if it is published or not. I think that most of the API fuctions have a published or unpublished mode.
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don't know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 24495
                  • 407 Posts
                  Here is an example for the travel prices (TV names from german words, comments translated). The snippet call in the travel detail pages template is:
                  [[reisePreise]]

                  without any parameters because I don’t need them. It collects all necessary information from TVs and returns the formatted result.

                  This is the snippet:
                  <?php
                  $id= (isset($id))? $id : $modx->documentIdentifier;
                  $pr1 = $modx->getTemplateVar('reisePreis1',"*",$id); // price per passenger
                  $pr1 = $pr1['value'];
                  $dz1 = $modx->getTemplateVar('reiseDZ',"*",$id); // if double room = "no" then take text of reiseDZ2 and ignore reiseEZ1
                  $dz2 = $modx->getTemplateVar('reiseDZ2',"*",$id); // text of reiseDZ2 
                  $ez1 = $modx->getTemplateVar('reiseEZ1',"*",$id); // additional charge for single room, if empty return "no additional charge"
                  $ez1 = $ez1['value'];
                  $pa1 = $modx->getTemplateVar('reisePA',"*",$id); // price for 1st passenger in partner campaign
                  $pa1 = $pa1['value'];
                  $pa3 = $modx->getTemplateVar('reisePA3',"*",$id); // price for single room in partner campaign
                  $pa3 = $pa3['value'];
                  $pri = $modx->getTemplateVar('reisePreisInfo',"*",$id); // additional information to prices like admission fees ...
                  
                  // common return of prices
                  if (($pr1 != '') && ($pa1 == '') && ($pa3 == '')) {
                  $output = '<h2><span>Preise pro Person:</span></h2>';
                  $output .= '<p>';
                  $pr1 = str_replace(',-', '', $pr1); $pr1 = str_replace('.-', '', $pr1); $pr1 = str_replace(',--', '', $pr1); $pr1 = str_replace('.--', '', $pr1); trim($pr1);
                  if (strpos($pr1, '.') > 1) { $pr1 = str_replace('.', ',', $pr1); $output .= $pr1.' €'; } else { $output .= $pr1.',– €'; }
                  
                  if ($dz1['value'] == 'ja') {
                  	if ($ez1 != '') {
                  		$output .= ' im Doppelzimmer, EZ-Zuschlag: ';
                  		$ez1 = str_replace(',-', '', $ez1); $ez1 = str_replace('.-', '', $ez1); $ez1 = str_replace(',--', '', $ez1); $ez1 = str_replace('.--', '', $ez1); trim($ez1);
                  		if (strpos($ez1, ',') > 1) {
                  			$output .= $ez1.' €.';
                  			} 
                  			else {
                  			$output .= $ez1.',– €.';
                  			}
                  		} else {
                  		$output .= ', kein EZ-Zuschlag.';
                  		}
                  	} else {
                  	$dz2 = nl2br($dz2['value']);
                  	$output .= ' '.$dz2;
                  	}
                  $output .= '</p>';
                  }
                  
                  // prices for partner campaign
                  if (($pr1 != '') && ($pa1 != '') && ($pa3 != '')) {
                  $output = '<h2><span>Partner-Aktion:</span></h2>';
                  $pr1 = str_replace(',-', '', $pr1); $pr1 = str_replace('.-', '', $pr1); $pr1 = str_replace(',--', '', $pr1); $pr1 = str_replace('.--', '', $pr1); trim($pr1);
                  if (strpos($pr1, '.') > 1) { $pr1 = str_replace('.', ',', $pr1); $pr1 = $pr1.' €'; } else { $pr1 = $pr1.',– €'; }
                  $pa1 = str_replace(',-', '', $pa1); $pa1 = str_replace(',--', '', $pa1); trim($pa1);
                  if (strpos($pa1, ',') > 1) { $pa1 = $pa1.' €'; } else { $pa1 = $pa1.',– €'; }
                  $pa3 = str_replace(',-', '', $pa3); $pa3 = str_replace(',--', '', $pa3); trim($pa3);
                  if (strpos($pa3, ',') > 1) { $pa3 = $pa3.' €'; } else { $pa3 = $pa3.',– €'; }
                  $output .= '<p>Der 2. Gast im Doppelzimmer bezahlt für diese Reise wirklich <strong>nur '.$pr1.'</strong>. ';
                  $output .= 'Der 1. Gast im Doppelzimmer bezahlt für diese Reise <strong>nur '.$pa1.'</strong>. ';
                  $output .= 'Preis im Einzelzimmer: '.$pa3.'.</p>';
                  }
                  
                  // return of additional info
                  if ($pri['value'] != '') {
                  $output .= $pri['value'];
                  }
                  
                  return $output;
                  ?>


                  All TVs requested are in the same document and are simple text fields. The snippet call is integrated in assigned template. Previewing the document unpublished the place containing the snippet call is empty. I’m not a skilled coder (and I think the code above is horrible for coders in hell grin ) but I wrote some other individual snippets for clients that work perfect. This works perfect too but only with published documents. And I never found a solution why results are empty on unpublished docs.

                  Maybe I can’t "getTemplateVar" if unpublished? Works this API function only with published docs? huh
                    • 7231
                    • 4,205 Posts
                    Yes, by default is looks only for published documents. I think that it will either returned published or unpublished so to get both you would need to check if the document is published or simply check both states, "if not this then try the other".

                    These are the available parameters:
                    getTemplateVar($idname, $fields, $docid, $published); 


                    http://wiki.modxcms.com/index.php/API:getTemplateVar
                    http://modxcms.com/gettemplatevar.html
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don&#39;t know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 24495
                      • 407 Posts
                      Need to do some tests. Thanks for the push to the right direction.