fxv_cms wrote:
1) Thank Alby - I tried the code you suggested, but without success : it provides some field names but not field values.
I don't understand... i believe i'm confused... no, wait! Maybe i'm not.
It was me who posted that code. Not Alby
That code i posted does exactly provide the content of any field of the content_props table.
E.g in your template (or content):
{get_content_props fields="param1"}
That will print out the content of the column named "param1" of the currently shown page.
I tried it by myself and it works fine.
fxv_cms wrote:
2) I expected the value of the "Extra Page Attribute 1" at the bottom of the "options" tab in the "Edit pages" of CMS [there are in fact 3 such extra attributes] to be stored in field "param1" of table content_props...
I expected the same thing...
fxv_cms wrote:
...but
for the same content_id, 6 records are created in table content_props :
- one with prop_name="content_en"
- one with prop_name="extra3"
- one with prop_name="extra2"
- one with prop_name="extra2"
- one with prop_name="pagedata"
- one with prop_name="target"
and the value entered as "Extra Page Attribute 1" is stored in field "content_en" of record which has prop_name="extra1"
So, that is why my code doesn't work properly for your purposes.
We just need to modify the code:
Code: Select all
global $gCms;
$db =& $gCms->GetDb();
$content_id = $gCms->variables['pageinfo']->content_id;
$fields = array();
$separator = '<br />';
$result = array();
if( isset($params['content_id']) ) {
$content_id = trim($params['content_id']);
}
if( isset($params['fields']) ) {
$fields = explode(',',trim($params['fields']));
}
if( isset($params['separator']) ) {
$separator= $params['separator'];
}
$i=0;
$query = "SELECT prop_name,content FROM ".cms_db_prefix()."content_props WHERE content_id=".$content_id;
if(!empty($fields)) {
$query .= " AND (";
foreach($fields as $f)
{
$i++;
$query .= "prop_name='".$f."'";
if($i<count($fields))
$query .= " OR ";
}
$query .= ")";
}
$dbresult = $db->Execute($query);
while($dbresult && $row = $dbresult->FetchRow()) {
$result[$row['prop_name']]['fieldname'] = $row['prop_name'];
$result[$row['prop_name']]['data'] = $row['content'];
}
// assign vars to smarty
if( isset($params['smarty']) && ($params['smarty']==true || $params['smarty'] == "true")) {
$smarty->assign('content_props', $result);
}
// or just print out the result
else {
$i=0;
foreach($result as $res) {
$i++;
echo $res['data'];
if($i<count($result))
echo $separator;
}
}
Same procedure as before.
The param
fields must contain a list of the prop_names as they where stored in the database.
Examples...
This will print out all content properties of the current page separated by a linebreak:
This will print out all content properties of the page with the content_id "15" separated by a linebreak:
Code: Select all
{get_content_props content_id="15"}
This will print out all content properties of the page with the content_id "15" separated by a comma:
Code: Select all
{get_content_props content_id="15" separator=","}
This will only print out the properties named "extra1" and "extra2" of the current page separated by a linebreak:
Code: Select all
{get_content_props fields="extra1,extra2"}
This will provide smarty variables that you can access after calling the UDT:
Code: Select all
{get_content_props smarty=true}
{$content_props.content_en.data}
{$content_props.target.data}
{$content_props.extra1.data}
or this one:
Code: Select all
{get_content_props smarty=true}
{foreach from=$content_props item=prop}
{$prop.fieldname}:{$prop.data}
{/foreach}
I hope this time it is what you're looking for.