[Example] How to do a dynamic block.useful for you!

Author Message

Bin LIU

Wednesday 09 July 2008 2:24:51 am

here, an example to explicate how to do a dynamic block.

We will make a block 8 random Recipes of the parent folder recipes node 999.

firstly, in the block.ini

#section_name + 'Layout_zone' + zone_number
#Solution for avoid all block in adding list of zone layout
#see http://ez.no/developer/forum/extensions/ez_flow/solution_for_avoid_all_block_in_adding_list_of_zone_layout
[CookingLayout_zone2]
AllowedTypes[]
AllowedTypes[]=RecipesRandom

[RecipesRandom]
Name=RecipesRandom
NumberOfValidItems=8
NumberOfArchivedItems=0
ManualAddingOfItems=disabled
FetchClass=LARandomObjects
FetchFixedParameters[]
FetchFixedParameters[Class]=recipe
FetchParameters[]
FetchParameters[Source]=nodeID
FetchParameters[Depth]=2
FetchParameters[Limit]=8
FetchParametersSelectionType[Source]=single
FetchParametersIsRequired[]
FetchParametersIsRequired[Source]=true
FetchParametersIsRequired[Depth]=true
FetchParametersIsRequired[Limit]=true
ViewList[]=8_recipes_random
ViewName[8_recipes_random]=8 Recipes Random
#Time for change the block after the crontab ezflow passed.
TTL=1800

and then, we should create the class FetchClass. so create larandomobjects.php in ezflow/classes/fetches

<?php
/**
 * LARandomObjects
 * @author LIU Bin <bin.liu@lagardere-active.com>
 */

include_once( 'extension/ezflow/classes/ezflowfetchinterface.php' );

class LARandomObjects extends eZFlowFetchInterface
{
    function fetch( $parameters, $publishedAfter, $publishedBeforeOrAt )
    {
        if ( isset( $parameters['Source'] ) )
        {
            $nodeID = $parameters['Source'];
            $node = eZContentObjectTreeNode::fetch( $nodeID, false, false ); // not as an object
        }
        else
        {
            $nodeID = 0;
        }

        $subTreeParameters = array();
        $subTreeParameters['AsObject'] = false;
        $subTreeParameters['Limit'] = isset( $parameters['Limit'] ) ? $parameters['Limit']:false;
        $subTreeParameters['Depth'] = isset( $parameters['Depth'] ) ? $parameters['Depth']:false;

        if ( isset( $parameters['Class'] ) )
        {
            $subTreeParameters['ClassFilterType'] = 'include';
            $subTreeParameters['ClassFilterArray'] = explode( ';', $parameters['Class'] );
        }

        $result = hfpFetchRandom::subTreeRandomByNodeID( $subTreeParameters, $nodeID );
        $fetchResult = array();
        foreach( $result as $item )
        {
            $fetchResult[] = array( 'object_id' => $item['contentobject_id'],
                                    'node_id' => $item['node_id'],
                                    'ts_publication' => $item['published'] );
        }

        return $fetchResult;
    }
}

?>

the class Fetch random see http://projects.ez.no/la_fetch_random

And in the ezflow bo, add source folder 999, config depth 2 and limit 8, and validate.

it works.

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Bin LIU

Tuesday 22 July 2008 2:33:19 am

I forgot the override.ini


[8_recipes_random]
Source=block/view/view.tpl
MatchFile=block/cooking/8_recipes_random.tpl
Subdir=templates
Match[type]=RecipesRandom
Match[view]=8_recipes_random

and my block/cooking/8_recipes_random.tpl


{def $valid_nodes = $block.valid_nodes}

<div class="contentLargeCol">
	<h3>{"Our favorites recipes :"|texttoimage('cooking_home')}</h3>
		{foreach $valid_nodes as $key => $recipe}
			<dl class="">
				<dt>{attribute_view_gui attribute=$recipe.data_map.image image_class='small_recipe' href=$recipe.url_alias|ezurl()}</dt>
				<dd><a href={$recipe.url_alias|ezurl()}>{$recipe.name}</a></dd>
			</dl>
		{/foreach}		
</div>

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Mircea Sabau

Thursday 24 July 2008 1:14:35 am

Another problem...

I followed your examples and seems to work ..
But when I publish a new article in source folder, the article in not diplayed... Only the initial articles are diplayed ...

I fetches articles with parameter

$subTreeParameters['SortBy'] = array( 'published', false ); // I need first the newest

Is correct?

Can you help me?

Bin LIU

Thursday 24 July 2008 5:10:13 am

it's normal

you must wait the cron pass, and the cron refresh the cache content paglayout. The new article will be show

active your cron ezflow

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Quynh Nguyen

Wednesday 18 February 2009 1:20:22 am

I followed your example:

- active extension: http://projects.ez.no/la_fetch_random

- I insert information in block.ini to ezflow/settings/block.ini.append.php

- create larandomobject2s.php in folder: ezflow/classes/fetches

- create file override.ini.append.php in ezflow/settings folder

- create file 8_recipes_random.tpl in ezflow/design/ezflow/override/templates/block/cooking

- clear cache and then add one more this block, and I got error:

Fatal error: eZ Publish did not finish its request

The execution of eZ Publish was abruptly ended, the debug output is present below.

JF Ozange

Thursday 19 February 2009 1:30:51 am

Hello Quynh Nguyen
I had the same error when i tried the dynamic blocs example from the EZ Flow setup docs.
I just changed the FetchClass=ezmLatestObjects by FetchClass=eZFlowLatestObjects to make it work.
Maybe your class is the problem ?

Bin LIU

Monday 18 May 2009 8:37:13 am

it is used in project elle international, and no error

in ezflow1 and ez4.0

perhaps it need some modif in the last version

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

A Fowler

Thursday 09 July 2009 1:19:02 pm

Is there a way to specify multiple classes to show, via the FetchFixedParameters[Class] parameter? For example (this is just a guess, and an attempt to show what I mean, though I have tested it and it doesn't work):

[DynamicMainBlock]
...
FetchFixedParameters[Class]=recipe
FetchFixedParameters[Class]=special_tip
...

Is this possible? Is there a different syntax for it?

Thank you!

A Fowler

Thursday 09 July 2009 1:42:37 pm

Never mind, I see the syntax in the Example text in the block.ini.append.php that I have. It shows this syntax:

# FetchFixedParameters[Class]=article;folder

I only got it to work, however, after both clearing the cache and removing and re-adding the dynamic block to the main layout on the front page.

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 18 2025 04:15:31
Script start
Timing: Jan 18 2025 04:15:31
Module start 'layout'
Timing: Jan 18 2025 04:15:31
Module start 'content'
Timing: Jan 18 2025 04:15:31
Module end 'content'
Timing: Jan 18 2025 04:15:31
Script end

Main resources:

Total runtime0.2788 sec
Peak memory usage4,096.0000 KB
Database Queries83

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 588.1875152.6563
Module start 'layout' 0.00600.0045 740.843839.5078
Module start 'content' 0.01050.2670 780.3516723.5234
Module end 'content' 0.27750.0013 1,503.875024.1016
Script end 0.2788  1,527.9766 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00361.3083160.0002
Check MTime0.00150.5386160.0001
Mysql Total
Database connection0.00100.366810.0010
Mysqli_queries0.198571.1885830.0024
Looping result0.00090.3116810.0000
Template Total0.229882.420.1149
Template load0.00200.702120.0010
Template processing0.227881.689920.1139
Template load and register function0.00010.035810.0001
states
state_id_array0.00220.778610.0022
state_identifier_array0.00140.497420.0007
Override
Cache load0.00170.6247600.0000
Sytem overhead
Fetch class attribute can translate value0.00090.328250.0002
Fetch class attribute name0.00100.3528100.0001
XML
Image XML parsing0.00100.369450.0002
class_abstraction
Instantiating content class attribute0.00000.0103130.0000
General
dbfile0.00090.3254150.0001
String conversion0.00000.003340.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 39
 Number of unique templates used: 7

Time used to render debug report: 0.0003 secs