Page 1 of 1
[ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 1:32 pm
by nicmare
Ich habe mehrere einfache statische Seiten (Typ Inhalt).
Nun möchte ich bspw. den Titel und den Content von SeiteX auf der Startseite anzeigen.
Kriege ich das mit dem Plugin hin? Oder wie komme ich an die Daten ran?
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 1:54 pm
by NaN
Sollte eigentlich problemlos möglich sein.
Mit dem Plugin kannst Du so ziemlich alles ausgeben lassen was immer Du willst.
Dazu gibt es aber eine recht umfangreiche doku:
http://wiki.cmsmadesimple.org/index.php ... ntent_dump
Du könntest es auch mit dem UDT
get_content_props versuchen.
(Nicht ganz so umfangreich aber wesentlich einfacher)
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 2:03 pm
by nicmare
Dein UDT scheint meinen Bedürfnissen zu entsprechen!
Ich konnte erfolgreich den Inhalt und die extra Felder auslesen.
Aber ich habs eher auf den Titel abgesehen und der wird anscheinend nicht ausgelesen. Wieso nicht?
Also weder erscheint er bei {get_content_props content_id="59"} noch wenn ich es direkt probiere mit fields="title"
edit: hab gesehen woran es liegt. du guckst ja nur in die tabelle cms_content_props. aber der Titel liegt direkt in cms_content . hmmm
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 2:52 pm
by NaN
Kannst ja auch mal diese Version probieren:
http://forum.cmsmadesimple.org/index.ph ... #msg161498
Da muss man nur die DB Abfrage etwas ändern:
Code: Select all
$query = "SELECT P.prop_name, P.content, P.content_id, C.*
FROM ".cms_db_prefix()."content C, ".cms_db_prefix()."content_props P
WHERE P.content_id = C.content_id";
Und weiter unten dann explizit jede Eigenschaft die man haben möchte hinzufügen (habs nicht getestet):
Code: Select all
while($dbresult && $row = $dbresult->FetchRow()) {
$result[$row['content_alias']][$row['prop_name']]['prop_name'] = $row['prop_name'];
$result[$row['content_alias']][$row['prop_name']]['data'] = $row['content'];
$result[$row['content_alias']]['content_id'] = $row['content_id'];
$result[$row['content_alias']]['content_alias'] = str_replace("-","_",$row['content_alias']);
// weitere Eigenschaften:
$result[$row['content_alias']]['title'] = $row['content_name']; // titel der seite
// ...
}
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 3:02 pm
by nicmare
naja, ich probiers grad mal mit dem content dump plugin aber raff es noch nicht ganz.
man kann sachen ja gut selektieren mit {$dump[n]->content->title}. blos finde ich das etwas blöd da sich n verändert, wenn man die Reihenfolge der Seiten ändert. Besser wäre es, wenn man die content_id nimmt.
Wie müsste die Abfrage dann aussehen ? habe mir mal $dump ausgeben lassen:
Code: Select all
stdClass Object
(
[item] => 0
[content] => stdClass Object
(
[id] => 59
[alias] => Nachrichtenbox
[title] => Nachrichten
[show] => 0
[active] => 1
[data] => Lorem ipsum dolor<br /><br />Lorem ipsum dolor sit amet Nam liber tempor cum soluta. Nam liber tempor cum soluta nobis eleifend option. Lorem ipsum dolor sit amet ibh euismod tincidunt.<br /><br /><!-- Add code here that should appear in the content block of all new pages -->
)
[parents]…
also ich will nur den Titel von content_id 59 anzeigen lassen.
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 3:14 pm
by NaN
Versuchs mal so:
Code: Select all
{content_dump this_only=59 assign=dumps}
{foreach from=$dumps item=dump}
{$dump->content->title}
{/foreach}
Da du ja nur ein Objekt hast, dürfte das alles sein.
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 3:19 pm
by nicmare
das entwickelt sich schon wieder zu so einer nervigen CMSms Angelegenheit.
Wenn ich das
{content_dump this_only=59 assign=box1}
über packe, bekomme ich mit {$box1|print_r} meine Werte angezeigt aber kann auf diese im nicht zugreifen.
Wenn ich das
{content_dump this_only=59 assign=box1}
in packe, bekomme ich mit {$box1|print_r} keine Werte angezeigt.
Ich peils net
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 3:23 pm
by NaN
Das liegt daran, dass der Head erst nach dem Body verarbeitet wird.
Wo lässt Du Dir denn die Werte anzeigen?
Setz mal in der config.php $config['process_whole_template'] = true;
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 3:42 pm
by nicmare
ich bin jetzt wieder auf dein UDT zurückgesprungen da mir das mit dem content dump zu kompliziert war.
aber mti deinen modifikationen funktioniert es kaum noch.
bei
{get_content_props content_id="59" fields="content_en"}
wird nun alles angezeigt. also als hättet man {get_content_props content_id="59"}. das mit dem title funzt erst recht nicht.
so sieht das udt aus:
Code: Select all
global $gCms;
$db =& $gCms->GetDb();
$content_ids = array($gCms->variables['pageinfo']->content_id);
$content_aliases = array();
$props = array();
$prop_separator = '<br />';
$page_separator = '<hr />';
$result = array();
$order_by = "hierarchy";
$q = array();
$p = array();
$where_props = array();
$where_id = array();
$where_alias = array();
if( isset($params['content_id']) ) {
$content_ids = explode(",",trim($params['content_id']));
}
if( isset($params['content_alias']) ) {
$content_aliases = explode(",",trim($params['content_alias']));
}
if( isset($params['props']) ) {
$props = explode(',',trim($params['props']));
}
if( isset($params['prop_separator']) ) {
$prop_separator = $params['prop_separator'];
}
if( isset($params['page_separator']) ) {
$page_separator = $params['page_separator'];
}
$query = "SELECT P.prop_name, P.content, P.content_id, C.*
FROM ".cms_db_prefix()."content C, ".cms_db_prefix()."content_props P
WHERE P.content_id = C.content_id";
if( !empty($content_aliases) ) {
foreach($content_aliases as $c_alias) {
$where_alias[] = "C.content_alias = ?";
$p[] = trim($c_alias);
}
}
else if( !empty($content_ids) ) {
foreach($content_ids as $c_id) {
$where_id[] = "P.content_id = ?";
$p[] = trim($c_id);
}
}
if(!empty($props)) {
foreach($props as $f)
{
$where_props[] = "P.prop_name = ?";
$p[] = trim($f);
}
}
if(count($where_props) || count($where_alias) || count($where_id)) {
if(count($where_alias)) {
$q[] = " (".implode(" OR ",$where_alias).") ";
}
else if(count($where_id)) {
$q[] = " (".implode(" OR ",$where_id).") ";
}
if(count($where_props)) {
$q[] = " (".implode(" OR ",$where_props).") ";
}
if(count($q))
$query .= " AND ".implode(" AND ",$q);
}
$query .= " ORDER BY ".$order_by;
$dbresult = $db->Execute($query,$p);
while($dbresult && $row = $dbresult->FetchRow()) {
$result[$row['content_alias']][$row['prop_name']]['prop_name'] = $row['prop_name'];
$result[$row['content_alias']][$row['prop_name']]['data'] = $row['content'];
$result[$row['content_alias']]['content_id'] = $row['content_id'];
$result[$row['content_alias']]['content_alias'] = str_replace("-","_",$row['content_alias']);
// weitere Eigenschaften:
$result[$row['content_alias']]['title'] = $row['content_name']; // titel der seite
// ...
}
// assign vars to smarty
// you can use both params at once (but with different values)
if( isset($params['assign']) || isset($params['assign_as_array']) ) {
// first just the whole values as one string
if( isset($params['assign']) ) {
$return = array();
foreach($result as $res) {
$ret = array();
foreach($res as $prop) {
$ret[] = $prop['data'];
}
$return[] = implode($prop_separator,$ret);
}
$r = implode($page_separator,$return);
$smarty->assign(trim($params['assign']), $r);
}
// or more complex the whole result as array
// so you can play with it in your template via smarty
if( isset($params['assign_as_array']) ) {
$smarty->assign(trim($params['assign_as_array']), $result);
}
}
// or just print out the result
else {
$return = array();
foreach($result as $res) {
$ret = array();
foreach($res as $prop) {
$ret[] = $prop['data'];
}
$return[] = implode($prop_separator,$ret);
}
$r = implode($page_separator,$return);
echo $r;
}
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 7:11 pm
by NaN
Okay.
Letzter Versuch.
Nimm diesen Code:
Code: Select all
global $gCms;
$db =& $gCms->GetDb();
$content_ids = array($gCms->variables['pageinfo']->content_id);
$content_aliases = array();
$props = array();
$prop_separator = '<br />';
$page_separator = '<hr />';
$result = array();
$order_by = "hierarchy";
$q = array();
$p = array();
$where_props = array();
$where_id = array();
$where_alias = array();
$show_prop_name = false;
if( isset($params['show_prop_name']) && $params['show_prop_name'] == true && $params['show_prop_name'] != 'false') {
$show_prop_name = true;
}
if( isset($params['content_id']) ) {
$content_ids = explode(",",trim($params['content_id']));
}
if( isset($params['content_alias']) ) {
$content_aliases = explode(",",trim($params['content_alias']));
}
if( isset($params['props']) ) {
$props = explode(',',trim($params['props']));
}
if( isset($params['prop_separator']) ) {
$prop_separator = $params['prop_separator'];
}
if( isset($params['page_separator']) ) {
$page_separator = $params['page_separator'];
}
$attribs = array();
if( isset($params['attribs']) ) {
$_attribs = explode(",",trim($params['attribs']));
foreach($_attribs as $attr) {
$attribs[] = "C.".$attr;
}
}
$query = "SELECT " . (count($attribs) ? implode(',',$attribs) . ', ' : '') . "
P.prop_name, P.content, P.content_id AS id
FROM ".cms_db_prefix()."content C
LEFT JOIN ".cms_db_prefix()."content_props P
ON C.content_id = P.content_id";
if( !empty($content_aliases) ) {
foreach($content_aliases as $c_alias) {
$where_alias[] = "C.content_alias = ?";
$p[] = trim($c_alias);
}
}
else if( !empty($content_ids) ) {
foreach($content_ids as $c_id) {
$where_id[] = "C.content_id = ?";
$p[] = trim($c_id);
}
}
if(!empty($props)) {
foreach($props as $f)
{
$where_props[] = "P.prop_name = ?";
$p[] = trim($f);
}
}
if(count($where_props) || count($where_alias) || count($where_id)) {
$query .= " WHERE ";
if(count($where_alias)) {
$q[] = " (".implode(" OR ",$where_alias).") ";
}
else if(count($where_id)) {
$q[] = " (".implode(" OR ",$where_id).") ";
}
if(count($where_props)) {
$q[] = " (".implode(" OR ",$where_props).") ";
}
if(count($q))
$query .= implode(" AND ",$q);
}
$query .= " ORDER BY ".$order_by;
$dbresult = $db->Execute($query,$p);
while($dbresult && $row = $dbresult->FetchRow()) {
foreach($row as $prop_name => $prop_value) {
if($prop_name != 'prop_name' && $prop_name != 'content' && $prop_name != 'id' && !isset($result[$row['id']][$prop_name])) {
$result[$row['id']][$prop_name] = $prop_value;
}
}
$result[$row['id']][$row['prop_name']] = $row['content'];
}
// assign vars to smarty
// you can use both params at once (but with different values)
if( isset($params['assign']) || isset($params['assign_as_array']) ) {
// first just the whole values as one string
if( isset($params['assign']) ) {
$return = array();
foreach($result as $res) {
$ret = array();
foreach($res as $prop_name=>$prop_value) {
$ret[] = ($show_prop_name?$prop_name.": ":'') . $prop_value;
}
$return[] = implode($prop_separator,$ret);
}
$r = implode($page_separator,$return);
$smarty->assign(trim($params['assign']), $r);
}
// or more complex the whole result as array
// so you can play with it in your template via smarty
if( isset($params['assign_as_array']) ) {
$smarty->assign(trim($params['assign_as_array']), $result);
}
}
// or just print out the result
else {
$return = array();
foreach($result as $res) {
$ret = array();
foreach($res as $prop_name=>$prop_value) {
$ret[] = ($show_prop_name?$prop_name.": ":'') . $prop_value;
}
$return[] = implode($prop_separator,$ret);
}
$r = implode($page_separator,$return);
echo $r;
}
Nimm diese Anleitung (nicht die aus dem Wiki):
http://forum.cmsmadesimple.org/index.ph ... #msg161498
Aber folgenden Zusatz:
attribs: ist ähnlich wie props; damit kann man die Basis-Attribute eines jeden Inhalts ausgeben lassen (also das, was in der Tabelle Content ist)
Bsp:
Code: Select all
{get_content_props content_id=59 attribs="content_name"}
ergibt den Titel der Seite mit der ID 59.
Frag jetzt nicht wieso das Feld für dieses Attribut in der db nicht title sondern content_name heißt ::)
Ich kanns leider auch nicht ändern.
show_prop_name: true/false; damit kann man sich vor jeder Eigenschaft deren Namen ausgeben lassen
Bsp:
Code: Select all
{get_content_props content_id=59 attribs="content_name" show_prop_name=true}
ergibt
Und dann kann man das ganze auch einfach einem Array zuweisen ( achte darauf, dass man hier jetzt nicht über das Seitenalias, sondern über die SeitenID direkt auf die Elemente des Arrays zugreift):
Code: Select all
{get_content_props props="content_en" attribs="content_name" assign_as_array="content_props"}
{$content_props[$content_id].content_name} = Titel
{$content_props[$content_id].content_en} = Inhalt - allerdings nicht compiliert (also nix mit smarty plugins)
{capture assign="content"}{$content_props[$content_id].content_en}{/capture}
{eval var="$content"} = Inhalt - compiliert (smarty hat sich da ein bissel pissig wenn man arrays als wert direkt mit assign oder eval verarbeiten will - daher mit capture)
Im Zweifel einfach mal folgendes ausgeben lassen:
Code: Select all
{get_content_props content_id=59 assign_as_array="content_props"}
{$content_props|print_r}
(Sollte
alle Eigenschaften des Inhalts ausgeben. Auch title etc.)
Ich hoffe das bringts jetzt.
Ansonsten musst Du mal warten bis nhaak hier evtl. mal etwas zu den Problemen mit seinem Plugin sagt.
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 7:28 pm
by nicmare
ich glaube wir sind ziemlich nahe dran

.
wenn ich {get_content_props content_id=59 attribs="content_name"} benutze, wird mir alles angezeigt. Also u.a. content_en und content_name.
Code: Select all
{get_content_props content_id=59 assign_as_array="content_props"}
{$content_props|print_r}
ergibt
Code: Select all
Array
(
[content_id] => 59
[content_name] => Nachrichten
[type] => content
[owner_id] => 2
[parent_id] => 15
[template_id] => 23
[item_order] => 1
[hierarchy] => 00001.00001
[default_content] => 0
[menu_text] => Nachrichtenbox
[content_alias] => Nachrichtenbox
[show_in_menu] => 0
[collapsed] =>
[markup] => html
[active] => 1
[cachable] => 1
[id_hierarchy] => 15.59
[hierarchy_path] => home/Nachrichtenbox
[prop_names] => image,thumbnail,extra1,extra2,extra3,searchable,pagedata,disable_wysiwyg,target,content_en
[metadata] =>
[titleattribute] =>
[tabindex] =>
[accesskey] =>
[last_modified_by] => 2
[create_date] => 2010-06-08 15:13:51
[modified_date] => 2010-06-08 16:51:51
[secure] => 0
[image] => -1
[thumbnail] =>
[extra1] => TEST
[extra2] =>
[extra3] =>
[searchable] => 1
[pagedata] =>
[disable_wysiwyg] => 0
[target] =>
[content_en] => Lorem ipsum dolor<br /><br />Lorem ipsum dolor sit amet Nam liber tempor cum soluta. Nam liber tempor cum soluta nobis eleifend option. Lorem ipsum dolor sit amet ibh euismod tincidunt.<br /><br /><!-- Add code here that should appear in the content block of all new pages -->
)
Array
jetzt habe ich also noch
{get_content_props content_id=59 assign_as_array="content_props"}
{$content_props.content_name} und {$content_props->content_name} probiert. bei beiden kommt garkeine ausgabe
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 7:41 pm
by NaN
Mach doch einfach das, was ich schreibe

Von {$content_props.content_name} oder {$content_props->content_name} hab ich doch garnichts erwähnt.
Code: Select all
{get_content_props content_id=59 attribs="content_name" props="content_en" assign_as_array="content_props"}
{$content_props[59].content_name} => Titel
{$content_props[59].content_en} => Inhalt
Edit:
Ja, ist ein kleiner Fehler im UDT.
Wenn für den Parameter props oder attribs nichts angegeben wird, nimmt er dafür automatisch alle props bzw. alle attribs.
Ist nicht ideal aber mit dem assign_as_array sollte es klappen.
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 7:43 pm
by nicmare
jaaa okay. habe ich jetzt gemacht und es geeeeht

Daaaankeeee. wieder mal ein spitzen support

aber wieso muss man die content_id zweimal angeben?
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 7:52 pm
by NaN
Weil es ein verschachteltes array ist: Array( [59] => Array ( ['content_en'] => bla, ['content_name'] => title))
Man könnte auch mehrere Seiten ausgeben lassen.
Und die werden im Array mit ihrer id indiziert.
Also muss man, wenn man die Eigenschaften nicht in einer Foreach Schleife ausgeben lassen sondern direkt darauf zugreifen will jedesmal den index mit angeben.
Beim ersten Aufruf wird lediglich das Array dem Template zugänglich gemacht.
Und beim zweiten Aufruf sagt man, dass man aus diesem Array die Eigenschaften des Eintrags mit der ID 59 haben will.
Re: [ContentDump] ist das mit diesem Modul möglich?
Posted: Tue Jun 08, 2010 8:00 pm
by NaN
Hab den Code da oben mal noch geändert.
Wenn man keine attribs angibt, dann werden auch keine ausgegeben.
Wenn man alle attribs will (aber diese nicht kennt) dann einfach ein * verwenden.