Page 2 of 3

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Thu Jul 23, 2009 3:54 pm
by mozart_ar
I come here from wiki pages.

Now, we have in the cmsms core the tag: page_attr

Use example:

Code: Select all

{page_attr key="extra1"}
Very useful. Thanks!

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Mon Sep 14, 2009 5:16 pm
by leerraum
thats great!

I'm asking myself how I can use this to get the fields of several pages, alike:

{get_content_props assign_as_array=pages}

{foreach page under a defined page}

{foreach from=$pages item=page}
  ID: {$page.content_id}

  ALIAS : {$page.content_alias}

  {foreach from=$page item = prop}
      {$prop.prop_name}: {$prop.data}

  {/foreach}
{/foreach}

{/foreach}

any ideas?

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Tue Sep 15, 2009 7:52 am
by leerraum
nobody? I thought about a menumanager template to retrieve the sites subsites, but I dont have the slightest clue how to include this tag into this template.

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Tue Sep 15, 2009 8:44 pm
by leerraum
ok, solved myself, so don't  ::) if it's not a neat solution.

I used the menumanager module and modfied the minimal template with NaNs tag.

Code: Select all

{if $count > 0}
{foreach from=$nodelist item=node}

				{get_content_props content_id=$node->id assign_as_array=content_props}
				
				
				{foreach from=$content_props item=page}
				   ID: {$page.content_id}<br />
				   ALIAS : {$page.content_alias}<br />
				   {foreach from=$page item = prop}
				   {* enter required property name here. for ex.: 
						{if $prop.prop_name == 'extra1'}
							... do something ...
						{/if}
						{if $prop.prop_name == 'custompropertyname'}
							... do something ...
						{/if}				   
				   *}
					  {$prop.prop_name}: {$prop.data}<br />
				   {/foreach}
				{/foreach}
				
{/foreach}
{/if}

call it like this

Code: Select all

{menu template="yourtemplatename.tpl" start_element="1.3.1" show_root_siblings="1"}
with this you can get every property of a bunch of pages stored at a certain level. this could be helpfull if you want to show a gallery overview for those pages, to be specific for a reference list.

any suggestions to improve this?

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Fri Sep 25, 2009 10:00 am
by johnmck
Hi,
I'm trying to use extra field 1 to output the code for albums

put when I place the code into it , it just spits out the code, not the album

{cms_module module='album' albums="24"}
1
h

It also spits out a 1 and a h after it!

In my template I have: {get_content_props props="extra1"}

>> Ok I just noticed the new tag {page_attr key="extra1"}
It's spitting out the contents of my extra field 1  {cms_module module='album' albums="24"} directly onto the page - but I want it to execute this code!

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Mon Sep 28, 2009 3:55 pm
by NaN
You need to assign the output to a variable and use that variable when calling the album.
Otherwise the call of the tag will be handled as the value of that param.
Smarty does not evaluate tags inside of tags. (This may change in a later smarty version)
That means

Code: Select all

{cms_module module="Album" albums="{get_content_props props='extra1'}"}
will let the album Module search for an Album called exactly "{get_content_props props='extra1'}" and not for the result of that tag.

Try this:

Code: Select all


{get_content_props props="extra1" assign="extra1"}
{cms_module module='album' albums="$extra1"}

or this one:

Code: Select all


{get_content_props assign=content_props}
{cms_module module='album' albums="$content_props.$page_alias.extra1.data"}

I don't know if the tag {page_attr} has a parameter where you can assign the output to a variable.
Just try it ;)
It might be similar.

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Thu Oct 01, 2009 9:44 am
by nchankov
The new page_attr plugin can asign a parameter to a variable this way:

Code: Select all

{page_attr key="extra1" assign="myParam"}
Later you can print the new variable myParam by

Code: Select all

{$myParam}
or use in conditional structure like:

Code: Select all

{if $myParam eq "yes"}
...do something...
{/if}
Hope that helps :)

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat Apr 24, 2010 9:59 am
by Pythoniels
Hi all,

I am trying to add extra fields but on a moment i saw this topic and using the extra page attribute. But i have a little problem now, these scripts work fine but show a lot of information i don't need. I only need to show the extra paga attribute 1,2,3 and nothing more. I deleted some lines in these scripts but without succes.

it's not a big problem to just show those extra page attributes, i need a script that works with a echo. Because if the EPA is in use, it has to show something in a table. If it's not in use, it doesn't need to be show.

Can anybody help me???

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat Apr 24, 2010 10:45 am
by NaN
Meanwhile there are so many possibilities to get those fields.
Last times i prefer to use the variable {$content_obj} since all page related things we need are already in there so we don't need to use an UDT that bothers the database for things we already have.
Try this:

Code: Select all


{$content_obj->mProperties->mPropertyValues.extra1}
{$content_obj->mProperties->mPropertyValues.extra2}
{$content_obj->mProperties->mPropertyValues.extra3}

(You can do this with any content prop ;) )

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat Apr 24, 2010 1:22 pm
by Pythoniels
@NAN: Yes I know. Reading the extra page attribute isn't the problem. I created two page to make it more clear for you.

Page 1: This is how it has to be WITH pictures:
http://www.aircrafts.nl/index.php?page=testje2

Page 2: This is how it needs to be WITHOUT pictures:
http://www.aircrafts.nl/index.php?page=airbus-a300

BUT it's not like Page 2, it's like this:
http://www.aircrafts.nl/index.php?page=testtttt

Note the ugly "Foto's" table on the last one ;)

I hope this is more clear.

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat Apr 24, 2010 3:51 pm
by NaN
Sorry but i don't get the point.
Pythoniels wrote:
I only need to show the extra paga attribute 1,2,3 and nothing more.
And this is exactly what

Code: Select all


{$content_obj->mProperties->mPropertyValues.extra1}
{$content_obj->mProperties->mPropertyValues.extra2}
{$content_obj->mProperties->mPropertyValues.extra3}

or

Code: Select all


{page_attr key="extra1" assign="myParam"}
{$myParam}

does.

So where is the problem?
Showing the three pages makes nothing clear to me since i don't have any clue what i am actually seeing there.
How does the template code look like?
What images are you talking about?
(Sorry if i'm a bit dumb here, but i just need more info)
Pythoniels wrote:
it's not a big problem to just show those extra page attributes, i need a script that works with a echo. Because if the EPA is in use, it has to show something in a table. If it's not in use, it doesn't need to be show.

Can anybody help me???
So what you actually need might be just a bit smarty logic, isn't it?
Maybe something like this?

Code: Select all


{if $content_obj->mProperties->mPropertyValues.extra1 != ''}

Do something here

{/if}

So "Do something here" only happens if there is actually some value within the extra 1 attribute.
Is that what you're looking for?

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat Apr 24, 2010 9:22 pm
by Pythoniels
NaN wrote:So what you actually need might be just a bit smarty logic, isn't it?
Maybe something like this?

Code: Select all


{if $content_obj->mProperties->mPropertyValues.extra1 != ''}

Do something here

{/if}

So "Do something here" only happens if there is actually some value within the extra 1 attribute.
Is that what you're looking for?
Yes, that's exactly what I'm looking for. The thing where it's all about is on the bottom of the pages. It's all about the 'fotos' section.

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat May 01, 2010 12:26 pm
by Pythoniels
Well i tried this code but without succes:

BEGIN CODE

{if $content_obj->mProperties->mPropertyValues.extra1 != '1'}
 
   Foto's
 
 
   

{$content_obj->mProperties->mPropertyValues.extra1} {$content_obj->mProperties->mPropertyValues.extra2} {$content_obj->mProperties->mPropertyValues.extra3}
   
 

{/if}

END CODE


I need something that IF extra 1 is empty, the text in red doesn't appear.
But if that field is not empty, it does need to show this because it looks much better.

Now it's like this: http://www.aircrafts.nl/index.php?page=testtttt  (check the bottom: foto's. It's text only but that's not good. It shouldn't be displayed at all.)

i hope this is more clear.

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat May 01, 2010 12:59 pm
by NaN
Pythoniels wrote:
I need something that IF extra 1 is empty, the text in red doesn't appear.
But if that field is not empty, it does need to show this because it looks much better.
So why don't you check if it actually is empty?

{if $content_obj->mProperties->mPropertyValues.extra1 != '1'} is wrong. That means the text will only be hidden if extra1 contains "1".

Try this instead (what was already mentioned above) :

{if $content_obj->mProperties->mPropertyValues.extra1 != ''}

Re: Create a user-defined tag to retrieve a field value from table 'cms_content_pro'

Posted: Sat May 01, 2010 3:07 pm
by Pythoniels
Oh I see. Well you probably noticed i'm a noob in php haha. I thought it needed a value. It works fine now! Thank you very much.

Is it possible to add an extra4 field btw?