Forums / Developer / how to make template override based on subtree?

how to make template override based on subtree?

Author Message

Vytautas Germanavičius

Thursday 31 March 2005 5:25:46 am

I have 2 sections:

-Public - this section is accessible to everyone.
-Protected - this section is accessible only to registered users.

I made different templates for both sections:
- in Public section users can see only preview of article
- in Protectes section registered users can see full view of article

I put all articles to protected section, and for some articles I added locations to public section.

Problem: shared articles in public section are shown using templates from Protected section

Someone offered to make "template override based on subtree". How to make it? Where to find information about it, because i cannot find nothing simmilar in
http://ez.no/ez_publish/documentation/customization/custom_design/override_templates

{set-block scope=root variable=cache_ttl}0{/set-block}

Eirik Alfstad Johansen

Thursday 31 March 2005 5:54:06 am

Hi vytis,

Check out this thread by Bård:

http://www.ez.no/community/forum/general/multiple_section_assignment/re_multiple_section_assignment__11

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Vytautas Germanavičius

Thursday 31 March 2005 10:51:47 pm

i did not found clear description, how to use that mystical url_alias... :(

I made:

[product_line]
Source=node/view/line.tpl
MatchFile=product_line_klientams.tpl
Subdir=templates
Match[class_identifier]=product
Match[url_alias]=produktai__3

[product_line]
Source=node/view/line.tpl
MatchFile=line/product.tpl
Subdir=templates
Match[class_identifier]=product

but nuw products in page /index.php/shop/produktai__3/indu_prieziura
are shown using default template, neither line/product.tpl nor product_line_klientams.tpl

{set-block scope=root variable=cache_ttl}0{/set-block}

Bård Farstad

Wednesday 20 April 2005 12:49:08 am

I have answered a similar question in the thread:
http://ez.no/community/forum/setup_design/what_should_be_written_in_match_url_alias_alias_of_node_or_alias_of_parent_node

This should contain the information needed about subtree override.

--bård

Documentation: http://ez.no/doc

Vytautas Germanavičius

Wednesday 20 April 2005 1:54:35 am

I checked
http://www.ez.no/community/forum/general/multiple_section_assignment/re_multiple_section_assignment__11
http://ez.no/ez_publish/documentation/customization/custom_design/override_templates
http://ez.no/community/forum/setup_design/what_should_be_written_in_match_url_alias_alias_of_node_or_alias_of_parent_node
http://ez.no/community/forum/developer/problem_with_sections_shared_articles_in_one_section_are_shown_using_templates_from_another_section
http://ez.no/community/forum/developer/how_to_make_template_override_based_on_subtree
http://ez.no/community/forum/developer/url_alias_doesn_t_work
http://ez.no/community/forum/developer/what_should_be_written_in_match_url_alias_alias_of_node_or_alias_of_parent_node
http://ez.no/community/forum/developer/can_someone_send_me_example_of_match_url_alias
and other , but oneone answered to my question :(

My conclusion i see that Match[url_alias] does NOT work. It does the same as Match[node].
I posted some bugs according this this or close related problems:
http://ez.no/bugs/view/6482
http://ez.no/bugs/view/6481
http://ez.no/bugs/view/6484

So, as i see for the moment, eZ do not anything for applying templates for the tree. :(
Or does it?

i have such situation (simplified):

news (section0)
|____Folder1 (section1)
|    |____Article1 (section1)
|____Folder2 (section2)
    |____Article2 (section2)
Hardware (section1)
|____Folder1(section1)
    |____Article1(section1)
    |____Article11(section1)
Software (section2)
|____Folder2(section2)
    |____Article2(section2)
    |____Article22(section2)

section0 must have red backgroud and show preview information with small images
section1 must have green backgroud and original layout with big images
section2 must have blue backgroud and different layout

Articles to section0 are added using "add new location". And are dicplayed using style from original location.

so to apply template of section0 to news/Folder1/Article1 i tried to write

 
Match[url_alias]=news
or
Match[url_alias]=/news
or
Match[url_alias]=/news/


Nothing works. it started to work, only if i specified :

 
Match[url_alias]=news/Folder1/Article1


It works, only if i specify exact url to article, but this has no sense, because everything in folder news (section0) are changed every day. So i cannot change overrides every time i enter something new in news...

{set-block scope=root variable=cache_ttl}0{/set-block}

Sebastiaan van der Vliet

Tuesday 26 February 2008 3:00:55 am

<b>sub_tree match override</b>

<i>Match on [url_alias]: issues in a multilingual site</i>
Using the [url_alias] as an match condition for the override system turned out to be problematic when used on a multilingual website. We ran into several problems. The first issue is related to the management of the override.ini.append.php file. We are using a sym linked override.ini.append.php file for the various siteaccesses (one siteaccess per language), in order to simplify maintenance of the site. Using the url_alias meant we had to set up separate url_alias matches for the various languages, either as separate override files per language, or additional entries in the shared override file (sym linked file). The second issue had to do with special characters in the url_alias: for some reason these were not picked up correctly from the override.ini.append files per language (in particular Polish) when using utf8_unicode_ci. We considered only using English nice urls, but it appeared not to be possible to disable the translated nice urls.

<i>Match on [sub_tree]</i>
In order to avoid the issues related to the translations of url_aliases, we have modified the kernel files to allow for a match condition on sub_tree:

[pagelayout_subtree_news]
Source=pagelayout.tpl
MatchFile=pagelayout-subtree-news.tpl
Subdir=templates
Match[sub_tree]=/1/2/130/ 

The subtree value is referring to the 'path_string' field in the 'ezcontentobject_tree', and is a value that is shared across the various languages. The numbers between de slashes represent the node_ids

We modified the following files:

In kernel\classes\eznodeviewfunctions.php (ezp version 3.10.0) we added array( 'sub_tree', $node->attribute( 'path_string' ) ), to the $keyArray that starts at line 93 and $contentInfoArray['sub_tree'] = $node->attribute( 'path_string' ); to the $contentInfoArray that starts at line 176. In addition, we added array( 'sub_tree', $Result['content_info']['sub_tree'] ), to the $keyArray that starts at line 383.

In kernel/common/eztemplatedesignresource.php at line 522, directly after the match condition for the url_alias, we added a match condition for subtree in a else if statement:

 if ( $conditionKey == 'url_alias' )
                                {
                                    $matchCondition .=
                                        "( strpos( \$matchKeys[\\'url_alias\\'],  \\'" . $customMatch['conditions']['url_alias'] . "\\' ) === 0 ) )";
                                } else if ($conditionKey == 'sub_tree' )
                                {
                                	 $matchCondition .=
									    "( strpos( \$matchKeys[\\'sub_tree\\'],  \\'" . $customMatch['conditions']['sub_tree'] . "\\' ) === 0 ) )";

                                }
                                else
                                {
                                    $matchCondition .=
                                        "( is_array( \$matchKeys[\\'$conditionKey\\'] ) ? " .
                                        "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'$conditionKey\\'] ) : " .
                                        "\$matchKeys[\\'$conditionKey\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )";
                                }

Possibly the file kernel\classes\ezcontentcache.php also needs to be modified, by adding 'sub_tree' => [some value], to the $contentInfo array at line 237.

Can anybody think of any negative implications of these modifications?

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.