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.]