Fetching class name and class identifier

Author Message

John Smith

Wednesday 14 December 2005 10:14:55 am

Hi there,

Hope someone can help me. I just want to know how to fetch class name and class identifier in the templates.

thanks.

Ole Morten Halvorsen

Wednesday 14 December 2005 11:05:39 am

Have you had a look at the fetch functions in the doc?
http://ez.no/doc/ez_publish/technical_manual/3_6/reference/template_fetch_functions

To fetch a class see:
http://ez.no/doc/ez_publish/technical_manual/3_6/reference/modules/content/fetch_functions/class

If you already have a node or an object you don't have to fetch anything, eZ publish will do it for you.

{$node.object.content_class|attribute(show)}

Senior Software Engineer - Vision with Technology

http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh

eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578

John Smith

Thursday 15 December 2005 12:56:01 am

hi ole,

thanks for your kind help mate, very useful.

One another thing if you can help. I want to fetch forum topic name in the forum reply template.

Cheers.

Paul Forsyth

Thursday 15 December 2005 3:29:09 am

I think the forum topic is the parent of the reply, so:

{$node.parent.name}

should do it.

Paul

John Smith

Thursday 15 December 2005 4:32:43 am

hi paul,

thanks for your kind reply.

Fetching parent node works fine for the forum reply while editing the forum reply, but that does not work while creating new forum reply.

Because system is creating a new object id when you press new forum reply and there is no parent for that object id untill you click "send for publishiing" button.

Am i right? If yes, how to fetch parent id means forum topic name or id while creating a new forum reply.

Please help.

cheers.

Paul Forsyth

Thursday 15 December 2005 4:52:21 am

According to:

http://ez.no/doc/ez_publish/technical_manual/3_6/templates/the_pagelayout/variables_in_pagelayout

You should be able to access $path or $content_info to find out where you currently are. From the path you can obtain the parent node id then consequently the parent node and its name.

Paul

John Smith

Thursday 15 December 2005 5:12:55 am

hi paul,

let me explain you the problem. what i am trying to do is to hide the subject input box in the forum reply page, because i dont want any subject every forum reply. I am also sending forum topic name as a hidden input field

All the alteration are in \design\news\temlates\content\datatype\edit\ezstring.tpl.

In that template i want to fetch forum topic name or id. I am not getting any thing. nothing from $path or $content_info.

Editing a forum reply is working fine.

I am using $attribute.object.main_parent_node_id.

But using the same variable generates errors for new forum reply.

Please help if you can.

cheers.

Paul Forsyth

Thursday 15 December 2005 5:52:09 am

One thing about hiding attributes like this is you have to make two hidden input fields, eg:

{* Hide field *}
<input type="hidden" name="ContentObjectAttribute_data_text_{$attributes.item.id}" value="{$attributes.item.content.input.input_xml|wash( xhtml )}" />
<input type="hidden" name="ContentObjectAttribute_id[]" value="{$attributes.item.id}" />

where the item.id is your attribute id you want to hide. the second input is the important part here because the system expects an array of all attribute ids, so your hidden attribute must be accounted for.

Because of this i would override and edit:

design/standard/templates/content/edit_attribute.tpl

instead of ezstring. It is a level higher than the ezstring edit template. Its then easier to use logic like:

{if eq($attributes.item.contentclass_attribute_name, "Somename")}
Show attribute
{else}
Hide attribute
{/if}

If you are trying the $path and $content_info variables at the ezstring level this might explain why they are empty. They will only be set in the top level content/edit.tpl.

Paul

John Smith

Thursday 15 December 2005 6:35:01 am

hi paul,

thanks for you kind help mate.

I know i am wrong. the code i am doing is written pls have a look

{section name=ContentObjectAttribute loop=$content_attributes sequence=array(bglight,bgdark)}
	<div class="block">
		{* only show edit GUI if we can edit *}
		{section show=and(eq($ContentObjectAttribute:item.contentclass_attribute.can_translate,0), ne($object.default_language,$ContentObjectAttribute:item.language_code) ) }
			<label>{$ContentObjectAttribute:item.contentclass_attribute.name|wash}</label>
			<div class="labelbreak"></div>
			
			<input type="hidden" name="ContentObjectAttribute_id[]" value="{$ContentObjectAttribute:item.id}" />
			{attribute_view_gui attribute_base=$attribute_base attribute=$ContentObjectAttribute:item}
	</div>
		{section-else}
			<label{section show=$ContentObjectAttribute:item.has_validation_error} class="validation-error"{/section}>{$ContentObjectAttribute:item.contentclass_attribute.name|wash}</label>
			<div class="labelbreak"></div>
			<input type="hidden" name="ContentObjectAttribute_id[]" value="{$ContentObjectAttribute:item.id}" />
			{if eq($ContentObjectAttribute:item.contentclass_attribute.name|wash, "Subject")}
				<input type="hidden" name="ContentObjectAttribute_data_text_{$ContentObjectAttribute:item.id}" value="Re: New Forum" />	
			{ else }
				{attribute_edit_gui attribute_base=$attribute_base attribute=$ContentObjectAttribute:item}
			{/if}
	</div>
		{/section}
{/section}

I am confused mate, please help. I know what u saying is right.

Can you please explain me where do the changes. I shall be very thankful to you.

thanks.

Paul Forsyth

Thursday 15 December 2005 6:47:26 am

Thats close. Put the <input type="hidden" name="ContentObjectAttribute_id[]"... field into the if statement.

What results are you getting?

John Smith

Thursday 15 December 2005 7:03:09 am

Paul, I think i dont need to put another line there, it above the if statement used for both case. The html output is given below have a look

<div class="block">
<label>Subject</label>
<div class="labelbreak"></div>
<input type="hidden" name="ContentObjectAttribute_id[]" value="1395" />
<input type="hidden" name="ContentObjectAttribute_ezstring_data_text_1395" value="Re: <Topic Forum Name>" />
</div>
<div class="block">
<label>Message</label>
<div class="labelbreak"></div>
<input type="hidden" name="ContentObjectAttribute_id[]" value="1329" />
<textarea class="box" name="ContentObjectAttribute_data_text_1329" cols="70" rows="10">
hi,this is new forum reply....
</textarea>
</div>

Please guide.

Another thing paul how to fetch parent node for the forum reply...

Paul Forsyth

Thursday 15 December 2005 7:10:00 am

Ok, so does the forum reply submit for you now?

John Smith

Thursday 15 December 2005 7:14:45 am

Another thing paul how to fetch parent node for the forum reply...

Another straight way function. Or do i need to use fetch statement.

Paul Forsyth

Thursday 15 December 2005 7:22:28 am

Try a quick test. See if $path or $content_info is present in:

design/standard/templates/content/edit.tpl

and also your current edit_attribute template. If its present in edit.tpl simply override it and change the include call to something like:

{include uri="design:content/edit_attribute.tpl" path=$path}

Paul

John Smith

Thursday 15 December 2005 7:33:48 am

I can't find any sort of "path" word in \desgin\standard\templates\content\edit.tpl.

What to do?

By the way thanks for continous help paul

Paul Forsyth

Thursday 15 December 2005 7:47:28 am

NP!

What i meant was try something like {$path|attribute(show)}. But, ive just tried this locally and no go.

However, this will work in your edit_attribute.tpl

{let parent=fetch(content,node,hash(node_id, $object.parent_nodes[0]))}
{$parent|attribute(show)}
{/let}

Now you have the parent you can take its name as normal.

Paul

John Smith

Thursday 15 December 2005 7:52:34 am

that code is producing the output given below:

Attribute Type Value

nothing else.

John Smith

Thursday 15 December 2005 7:55:44 am

It is working.

Means it giving the output which i was looking for.

Thanks.

Paul Forsyth

Thursday 15 December 2005 8:01:56 am

Phew! Lovely :)

Glad we got there in the end.

Paul

John Smith

Thursday 15 December 2005 8:08:10 am

Hi Paul,

Mate thanks for your kind help, Everything is working fine now.

Really appreciated..

Keep helping ez community like Paul.

Cheers.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 01:05:54
Script start
Timing: Jan 19 2025 01:05:54
Module start 'layout'
Timing: Jan 19 2025 01:05:54
Module start 'content'
Timing: Jan 19 2025 01:05:54
Module end 'content'
Timing: Jan 19 2025 01:05:54
Script end

Main resources:

Total runtime0.7273 sec
Peak memory usage4,096.0000 KB
Database Queries128

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 589.2813152.6406
Module start 'layout' 0.00630.0040 741.921939.4609
Module start 'content' 0.01030.7155 781.3828728.7109
Module end 'content' 0.72570.0015 1,510.093832.1406
Script end 0.7272  1,542.2344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.5423160.0002
Check MTime0.00150.2091160.0001
Mysql Total
Database connection0.00160.213410.0016
Mysqli_queries0.620285.27401280.0048
Looping result0.00110.14941260.0000
Template Total0.691995.120.3460
Template load0.00310.432820.0016
Template processing0.688894.704020.3444
Template load and register function0.00010.018810.0001
states
state_id_array0.00120.162410.0012
state_identifier_array0.00280.384320.0014
Override
Cache load0.00300.40571120.0000
Sytem overhead
Fetch class attribute can translate value0.00090.126530.0003
Fetch class attribute name0.00110.1501200.0001
XML
Image XML parsing0.00030.044130.0001
class_abstraction
Instantiating content class attribute0.00000.0046200.0000
General
dbfile0.00100.1319100.0001
String conversion0.00000.001640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
20content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
26content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 56
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs