We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36931
    • 206 Posts
    Dear All,
    I am doing something new for my and is my structure, explication and question:

    I have a template call "tplNews"

    I have a document called "new" which is parent of the following document :

    I have servral child documents of "new", called "new1", "new2", "new3".

    All teh mentionned documents are linked to the template "tplNews"

    I created a snipest called "snpNews" which will extract the data from the table "modx_site_content".
    A while loop is extracting the data of "new1", "new2" and "new3"

    That snipest is called from the "new" document as the following:

    [[!snpNews? &page_id=`[[*id]]`]]

    	include($root.'manager/templates/site/sql/db_config.inc.php');
    	include($root.'manager/templates/site/sql/db_connect.inc.php');
    // Extract the parent id
    $sql_news = "SELECT * FROM modx_site_content WHERE parent LIKE ".$page_id." ORDER BY publishedon DESC";
    $query_news = mysql_query($sql_news)or die(mysql_error());
    $no_news = mysql_num_rows($query_news);
    if($no_news >= 1){
      	echo '<table class="news">';
    	while($data_news=mysql_fetch_assoc($query_news)){
    		echo '<tr class="row1"><td class="col1">';
    	  	echo date('d-m-Y',$data_news['publishedon']);
    	  	echo '</td><td class="col2">';
    	  	echo $data_news['pagetitle'];
    	  	echo '</td><td class="col3">';
    	  	echo '<a href="[[~'.$data_news['id'].']]" class="iframe">Detail</a>';
    	  	echo '</td></tr>';
    	  	echo '<tr class="row2"><td class="col1">';
    	  	echo 'Image';
    		echo '</td><td colspan="2" class="col2">';
    	  	echo $data_news['content'];
    		echo '</td></tr>';
    	}
      echo '</table>';
      	
      
    }
    

    This works fine.

    I also created 4 Template Variable and I provided it access to the Template called "tplNews"

    • [[*imageNew]]
    • [[*linkTarget]] (radio buttom : link || pdf
    • [[*linkPath]]
    • [[*pdfPath]]
    Those templates variable is not used with the "new" document. However, the 3 child documents, "new1", "new2" and "new3" use the template varaible in order to set an images, a pdf or a web link.


    My question is the following


    From my snipest "smpNew", I can create a MySQL jointure to extract data from pages (modx_site_content) and extract the value of the related template variable data from the table "modx_site_tmplvar_contentvalues"

    But in that way, I do all with MySQL requests.

    My question:

    Would I be possible to do it with PHP and template variable syntax?
    For exemple
    <?php
    // Matching to the extract page of modx_site_content
    if(!empty([[*ImageNew]])) echo '[[*ImageNew]]';
    
    if([[*linkTarget]]=="pdf") {
    echo '[[*linkPath]]';
    }elseif([[*linkTarget]]=="link"){
    echo '[[*pdfPath]]';
    }
    
    ?>
    


    Or is there another way to work with MODx Syntax?
    ... and not going thorugh the MySQL requests and searching in the database?

    Do see what I mean?
    I hope I was clear in my post?

    Many thank for your help and explicarion [ed. note: pierrot1010 last edited this post 12 years, 5 months ago.]
      • 36931
      • 206 Posts
      Or may be, I can ask you it more simply:

      How can I extract TV value, matching to a document ID, from a snippest?
        • 3749
        • 24,544 Posts
        You can't use MODX tags in a snippet, but you can do this:

        <?php
        $tvId = 12;
        $resourceId = 36;
        
        $tv = $modx->getObject('modTemplateVar', $tvId);
        
        if ($tv) {
            $tvRawValue = $tv->getValue($resourceId);
            $processedValue = $tv->renderOutput($resourceId);
        }
        
        
          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
          • 37809
          • 8 Posts
          I study illustration at the Academy of Art University in , I am torn between Italian and French. Italian is such a romantic language but I think I might get more use out of French, I dont know anyone who speaks Italian. I have to take a language anyway. What do you guys think?
          Rosetta Stone Latin America Spanish
            • 36931
            • 206 Posts
            Great!!
            This hep me a lot!!!
            But wht is the differenve between

            renderOutput() and
            tvRawValue()

            I searched on the NET a list of TV function, as above, but I could not find.
            Do you have link to give me?

            Both return the same value [ed. note: pierrot1010 last edited this post 12 years, 5 months ago.]