Forums / Developer / Creat new Class and template

Creat new Class and template

Author Message

Vins Prasad

Thursday 11 March 2010 9:17:17 pm

Hi,

I need to create a class which is design should be same as "FrontPage" but with four columns. Could you please someone let me know how I can do it.

Does it require creating a template also? Since I checked the "FrontPage" class attributes in edit mode and I found that the there is a template called "frontpage.tpl" which specify how the output should be. But I don't know how I can create such template for my new class.

Really appreciate your help on this.

Thank you,
Vins

Jean-Luc Nguyen

Wednesday 17 March 2010 7:22:39 am

Hello,

You can specify views for classes in override.ini.append.php

Take a look at default override.ini file.

http://www.acidre.com

Sandeep Kadam

Monday 22 March 2010 4:17:05 am

HI Vins,

You can create a new class by following below steps:

  1. Click on the "Setup" tab.
  2. Click on "Classes" - from within the menu on the left hand side.
    A list of class groups will appear.
  3. Click on "Content" (from within the list).
    A list of available classes will appear.
  4. Click on the "New class" button.
    The class edit page will appear.
  5. select the attributes which u need in your class. and add that attribute by clicking add attribute.
  6. click ok if you are done.

    till now you are ready with your class and now you have to override full.tpl for your class.
    Example code of override file"

    <div class="content"><h1>{$node.name|wash()}</h1>{attribute_view_gui attribute=$node.data_map.body}</div>

    you will require to override embeded and line tpl as per your requirement

    Thank you,
    Sandeep

Vins Prasad

Tuesday 23 March 2010 11:00:37 pm

Hi Sandeep/Nguyen, Thank for your replies.

I created a template by with following steps. my requirement was create a reusable content (text) box something like as a Login control which I need to add to many pages (not all pages) of my site without changing the inside content.

1. Create a Class with attributes
2. Create a tpl file for my design
3. add changes to the relevant ini files.

Finally my newly created class appeared among others and I can add it to pages by clicking "Create Here". Now I need to create a object from my class and fill relevant data so then its available for insert as a Object for my pages as much as times that i need. ie. I create the object using "Create Here", Fill data "Bla blaa blaa" then adding to any page that I need.

The problem is when I add object to a page, Its display as a link and need to click the link to see the content, but I need to show the content (text) directly in the page rather than a link. Could you please let me know how can I do that?

Thanks in advance and sorry for long reply.

Vins

Akhilesh Singh

Thursday 25 March 2010 2:32:10 am

HI Vins ,

I faced the same problem while creating class for form.

I solved it by creating an override for full.tpl for class.

Same thing is sandeep asking you to do after point 6.

If you are not aware how to create override.
please follow below steps:
Search for full.tpl in template list of design tab.

select "node/view/full.tpl"

click new override
select your extension in extension drop down {optional}

and your desired class in all classes drop down

the content of the overridden file will b similar as provided by sandeep:

{attribute_view_gui attribute=$node.data_map.body}

in place of "body" you will need to set your attribute name what you want to display.

Thank you,
Akhilesh

Lo' F.

Friday 02 July 2010 5:49:10 am

Hi guys,

I created a new class (holding just three attributes: name, body and tags) of which object's body content I want to be displayed in the home page.

When I inserted the object, from the drop-down list I seleted "full" view (since I don't want it to a link but just something which is there in the home page); however this makes the object appearing with all its details (version, name and so on) while I just want to have the content of its body attribute on screen.

As here explained, I created a new override full_classname from Design>Template>node/view/full.tpl of which matching file is full/classname.tpl, class_identifier:classname, just like this:

{* classname - Full view *}
<div class="content-view-full">
    <div class="class-classname">

        

{* Body. *}
        {if $node.data_map.body.has_content}
            <div class="attribute-long">
                {attribute_view_gui attribute=$node.data_map.body}
            </div>
        {/if}

    </div>
</div>

  
CancelCancel

..but yet the class' object comes up with all its details not just with the body's content.

What else do I have to do to get just the desired outcome?

Thanks in advance!

loredanaebook.it

Sandeep Kadam

Tuesday 06 July 2010 5:01:27 am

1. did you cleared cache after doing override.?

2. turn on debugging and check all overrides for the template
ie. in Template Used to render the page section check for Template loaded for below file
"node/view/full.tpl ".

this should show the file that you have overrided ie "full_classname". Let me know what you get :)

Thank you
Sandeep

Lo' F.

Tuesday 06 July 2010 10:40:54 am

Yes, I did. I cleared the cache after created the override.

In the Templates used to render the page section, for the Requested template "node/view/full.tpl", under Template loaded I get "extension/ezwebin/design/ezwebin/override/templates/full/frontpage.tpl" and under Template "full/frontpage.tpl".

...

loredanaebook.it

Sandeep Kadam

Wednesday 07 July 2010 12:14:36 am

what is the name of file that you created while overriding your full.tpl
is this frontpage.tpl .????

or any thing else .?

please provide the file name and path where that override file is stored

and the override condition in file "override.ini.append.php"
settings\siteaccess\<site_access>

Kévin S.

Wednesday 07 July 2010 1:01:20 am

Lo'F, if I understand well your problem, you want to show only the "body" attribute of your object on your frontpage ?

I would choose the "embed" view, since the "full" view is used to show all the content of nodes. Then, if the embed template does not show the object as you want, you override it. To check if your override is active, you can go in the class page of eZ Publish administration (use the button "Override templates" to show templates used for your class at the bottom of the page). If your template is not listed, check your template declaration in override.ini.append.php.

Lo' F.

Friday 09 July 2010 1:50:01 am

Sorry guys for haven't come back to you soon. Thanks for your reply.

I am a newbie to eZ and yet haven't fully entered into it..

That's exactly what I am trying to do, Kevin. Since I tried the several view options and couldn't get the desired outcome, I just followed the procedures from this post but I couldn't even get the generated override file listed in the used templates of debug: I just got that frontpage.tpl in place of it.

...

In the override templates section of the new created jquery class' details page I get listed:

Siteaccess: public
override: full_jquery
origin template: node/view/full.tpl
override template: design/admin2/override/templates/full/jquery.tpl

I added the following block in the override.ini.append.php (in setting/siteaccess/public/):

[full_jquery]
Source=node/view/full.tpl
MatchFile=full/jquery.tpl
Subdir=templates
Match[class_identifier]=jquery[full_jquery]

...

p.s.While creating the override (from Design->Templates->new override) I also got confused about what to enter into the fields, I just guessed: extension, I gave the ezwebin (the one I am working on), for the name, jquery (?), then selected jQuery class, all sections, and empty file. But really I don't know if I did right.

Thanks again...

loredanaebook.it

Kévin S.

Friday 09 July 2010 6:39:41 am

If you can't see your template in the debugging list, it is simply not called by eZ Publish.

Are you sure you are working on the good siteaccess ? The same one where you declared your template override ? You can check it in your url (try "eZPublish/index.php/public" if you're unsure).

"

I added the following block in the override.ini.append.php (in setting/siteaccess/public/)

"

If there is no problem here, you can check the attribute you give to the attribute_view_gui fonction in your frontpage.tpl this way :

{$node|attribute(show, 1)}
{$node.data_map|attribute(show, 1)}
{$node.data_map.body|attribute(show, 1)}

Also make sure the file /extension/[your extension]/design/[your extension]/override/templates/full/jquery.tpl exists.

In the last line of your template declaration, try removing "[full_jquery]" (I don't know why it is here).

In your "Ps" you are speaking about overriding a template using the administration interface ? I don't do it this way, I prefer editing directely files !

Lo' F.

Wednesday 11 August 2010 10:01:58 am

Hi guys, Sorry again for delay. I had some days off (..for my wedding) and now it's time for me to get back to work dealing with my ez project..

Well, I am sure it cannot be so complicated but yet I cannot figure out how the override works!

Thanks Kevin, you gave me a good hint since the siteaccess I was testing wasn't "public" but "ita"!
So I added the required block to setting/siteacess/ita/override.ini.append.php as follows:

[full_jquery]
Source=node/view/full.tpl
MatchFile=full/jquery.tpl
Subdir=templates
Match[class_identifier]=jQuery

I added a new full/jquery.tpl file inside "design/ezwebin/override/templates/" containing the following block of code:

{* JQuery - Full view *}<div class="content-view-full">
    <div class="class-jquery">
        <!--<h1>{$node.data_map.name.content|wash()}</h1>->
        {* Body. *}
        {if $node.data_map.body.has_content}
            <div class="attribute-long">
                {attribute_view_gui attribute=$node.data_map.body}
            </div>
        {/if}
    </div>
</div>

...

All "extension/ezwebin/design/ezwebin/override/templates/full/frontpage.tpl" contains is:

...
    <div class="columns-frontpage float-break">
        <div class="left-column-position">
            <div class="left-column">
            <!-- Content: START -->
                   {attribute_view_gui attribute=$node.object.data_map.left_column}
            <!-- Content: END -->
            </div>
        </div>
        <div class="center-column-position">
            <div class="center-column float-break">
                <div class="overflow-fix">
                <!-- Content: START -->
                    {attribute_view_gui attribute=$node.object.data_map.center_column}
                <!-- Content: END -->
                </div>
            </div>
        </div>
        <div class="right-column-position">
            <div class="right-column">
            <!-- Content: START -->
                  {attribute_view_gui attribute=$node.object.data_map.right_column}
            <!-- Content: END -->
            </div>
        </div>
    </div>
    <div class="attribute-bottom-column">
        {attribute_view_gui attribute=$node.object.data_map.bottom_column}
    </div>

...

I have been struggling all day long adding file here and there and now I am really confused since none of my attempts gave any result..

Here's the information I can give:
- The templates I am working with are placed inside "extension/ezwebin/design/ezwebin/templates".
- The full.tpl which seems to be connected with the inserted object is located inside design/standard/templates/content/view/full.tpl

All I need to do is inserting the only content of the body of my jquery class' object in the home page!

The folders structure of ez publish has become a maze for me now and I hope I can sort it out with your help!

Many many thanks!

loredanaebook.it

Kévin S.

Thursday 12 August 2010 6:08:14 am

Hi Lo's, congrats for your wedding ! :)

Indeed, ez folders are quite messy (I am just beginning to get used to the structure) !

You are currently working on the ezwebin extension, which override standard templates. This is why you have to create your system templates (those as pagelayout.tpl that are not directly linked to the current node) in /extensions/ezwebin/design/ezwebin/templates/ (No "override" folder here !).

Your view templates have to be in /extensions/ezwebin/design/ezwebin/override/templates/.

As you are overriding the template for a specific class, this is a view template. So it should be in /extensions/ezwebin/design/ezwebin/override/templates/full/. This folder is specified in your override declaration (the "Subdir" is relative to override/) :

[full_jquery]

Source=node/view/full.tpl
MatchFile=full/jquery.tpl
Subdir=templates
Match[class_identifier]=jquery

Note that this declaration is made in override.ini.append.php, located either in settings/siteaccess/<the_site_access_which_should_have_the_override> or in settings/siteaccess/override if this override must be active for all your siteaccesses.

I think your are messing up the [extension_design]/override/template folder with the [extension_design]/template/ folder.

If this is not the case, you can try to link your jquery object to your frontpage (with common relations) in the administration interface, then you can try to use this code to call the template you've created :

{def $jquery_obj=$node.object.related_contentobject_array[<index_of_jquery_object_in_relation_list>]}
{node_view_gui node=$jquery_obj.main_node view='full'}

PS : I've noticed in your template declaration, you are using "jQuery" for class identifier. Use only low-case for class and attribute identifier : "jquery" ! It might be the reason why your override is not working !

Lo' F.

Monday 16 August 2010 12:49:08 pm

Thank you Kévin! Your help has saved me hours!
I guess I am on the right track now on the way this override system works.

Even though for this new created "jquery" class I had to attempt something else, the steps you told me worked great to override the article.tpl and folder.tpl classes which I altered by adding overriding files inside extension/ezwebin/design/ezwebin/override/templates/full/ and line/.

...

Exactly dunno why but for this jquery object I had to override the content/view/full..

Once set the "inline template debug" on for the ita siteaccess, the jquery object had design/ezwebin/override/templates/content/view/full.tpl above it.

So I created the folder path brand new as above recalled and added this lines into the full.tpl file (commenting out all the other lines of the original copied full.tpl file)

{* view Full *}
{* Body. *}
<div>
{attribute_view_gui attribute=$object.data_map.body}
</div>

..and declared it in the settings/siteaccess/ita/override.ini.append.php

[full_jquery]
Source=content/view/full.tpl
MatchFile=content/view/full.tpl
Subdir=templates
Match[class_identifier]=jquery

..and this time it worked.

No way if I create a jquery.tpl inside design/ezwebin/override/templates/full/ and declare it as MatchFile=full/jquery.tpl, though! It doesn't work this way which is a bit strange to me, as it should, shouldn't it!?

But why for the folders and articles classes in the "Templates used to render the page" list the loaded template is respectively extension/ezwebin/design/ezwebin/override/templates/full/folder.tpl and article.tpl and yet for the jquery it returns extension/ezwebin/design/ezwebin/override/templates/full/frontpage.tpl and need to alter the content/view/full instead?
Tell me if I am wrong, has this anything to do with the object inserted in a Folder main node either than a FrontPage one, by any chance?

Thanks again!

loredanaebook.it

Lo' F.

Tuesday 17 August 2010 7:28:16 am

"

No way if I create a jquery.tpl inside design/ezwebin/override/templates/full/ and declare it as MatchFile=full/jquery.tpl, though! It doesn't work this way which is a bit strange to me, as it should, shouldn't it!?

"

...Forget about it!

I just figured out that the view override for this jquery class has to be inside the content/view folder.

- The default view .tpl files are inside design/standard/templates/content/view/

- The override jquery.tpl file goes inside design/ezwebin/override/templates/content/view/full/ ...embed/ ... and so on..

- settings/siteaccess/ita..eng...fre.../override.ini.append/php declaration:

[full_jquery]
Source=content/view/full.tpl
MatchFile=content/view/full/jquery.tpl
Subdir=templates
Match[class_identifier]=jquery

...

loredanaebook.it

Kévin S.

Tuesday 17 August 2010 8:47:52 am

You got it ! To obtain the path of the template you are creating, just concat the Subdir field with the Source field.

I think there is a content folder in this path because this object is not called as a node (otherwise it would be design/override/template/full), but rather as a content of the frontpage.

"

in the "Templates used to render the page" list

"

For template debugging, I don't use this list. Just check the box "Template Debug", then with firebug you look at the HTML code of the page. If you activate the comments you will be able to see when each template begins and ends. It's way handier than the templates used to render the page list, or even the inline template debug.

If you have other interrogations I'll be glad to help, not so long ago I was the one struggling with eZ folders. I'll just may take 1 or 2 days to answer as I'll be off for several days.

Cheers !

___

Kévin

Lo' F.

Saturday 28 August 2010 9:15:40 am

"

.. with firebug you look at the HTML code of the page. If you activate the comments you will be able to see when each template begins and ends. It's way handier than the templates used to render the page list, or even the inline template debug.

"

I have to tell you, man! This suggestion you gave me has made my life much easier when looking for matching templates and their location.

Thanks, Kévin!

loredanaebook.it

Gaetano Giunta

Saturday 28 August 2010 10:19:09 am

Another useful tip to help with template debugging: you can use the debug-log template function (http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_functions/debugging/debug_log) to send messages to the debug area at the bottom of the page. Using messages such as 'template X start', 'template X end' or concat('rendered at timestamp ',currentdate()) can help understanding what happens under the hood.

The ezdebug_tempalte_operator extension (http://projects.ez.no/ezdebug_template_operator) is also available

Principal Consultant International Business
Member of the Community Project Board