Customising forms

Author Message

James Packham

Monday 12 January 2004 5:31:14 am

Hi I'm trying to create a form where anonymous users can only see some of the fields and not others. I think this means that I can't just use a normal edit_attribute.tpl because it'll just display all the attributes of the object.

Does this mean that I have to create a custom edit template with each of the attributes? Is there an easier/better way? It's just that if I add attributes to my object at a later date then I'll have to edit the template as well to make them visible for editing...

Thanks in advance,

~James~

Tore Skobba

Monday 12 January 2004 7:17:37 am

Hi

I had a somewhat similar problem, users should enter their data. However, only SOME of this data should be available for viewing by all users. As such I had this template code:

<ul class="attribute_list">
{section name=ContentObjectAttribute loop=$node.contentobject_version_object.contentobject_attributes}
{section show=$:item.contentclass_attribute.name|begins_with("Restricted")|not()}
<li> {$ContentObjectAttribute:item.contentclass_attribute.name|wash}:
{attribute_view_gui attribute=$ContentObjectAttribute:item}</li>
{/section}
{/section}
{/let}

Here ALL attributes begning with "Restricted" are not shown, you could the same in your edit template, simply allow editing of all attributes which does not begin with "Restricted" or whatever. For more see here:

http://www.ez.no/developer/ez_publish_3/documentation/customization/tips_tricks/hiding_attribute_content

James Packham

Monday 12 January 2004 1:58:07 pm

I don't fully understand - how do I add this to the exisiting edit_attribute.tpl? I tried

{section show=and(eq($ContentObjectAttribute:item.contentclass_attribute.can_translate,0),
ne($object.default_language,$ContentObjectAttribute:item.language_code)) |begins_with("Restricted")|not()) }

and

{section show=and(eq($ContentObjectAttribute:item.contentclass_attribute.can_translate,0),
ne($object.default_language,$ContentObjectAttribute:item.language_code),
ne($:item.contentclass_attribute.name|begins_with("Restricted")|not()) ) }

Among others, with and without the ; But none of them worked. Where do I need to put your wizzy bit of code?

Thanks,

~James~

James Packham

Wednesday 14 January 2004 1:55:26 am

Yay! I figured out how to do it. Incase anyone's interested you can add the following section statement to an override of edit_attribute.tpl (the code in the middle is already in edit_attribute). This uses the name of the attribute to filter out the attributes you don't want.

All you have to do then is add the word restricted to the begining of the identifier for the attributes you don't want.

{section show=$ContentObjectAttribute:item.contentclass_attribute_identifier|begins_with("restricted" )|not()}
<label>{$ContentObjectAttribute:item.contentclass_attribute.name|wash}</label><div class="labelbreak"></div>
<input type="hidden" name="ContentObjectAttribute_id[]" value="{$ContentObjectAttribute:item.id}" />
{attribute_edit_gui attribute_base=$attribute_base attribute=$ContentObjectAttribute:item}

{/section}

Also bear in mind that this code is repeated in a section-else (though I'm not sure why, something to do with a different set of conditions).

Thanks for your help :)

~James~

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