eZ Community » Forums » Extensions » eZ Flow » [Example] How to do a dynamic...
expandshrink

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

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

Wednesday 09 July 2008 11:24:51 am - 8 replies

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.

Modified on Tuesday 22 July 2008 10:23:59 am by Bin LIU

Tuesday 22 July 2008 11: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>

Modified on Tuesday 22 July 2008 11:35:07 am by Bin LIU

Thursday 24 July 2008 10: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?

Thursday 24 July 2008 2:10:13 pm

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

Wednesday 18 February 2009 10: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.

Thursday 19 February 2009 10: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 ?

Monday 18 May 2009 5:37:13 pm

it is used in project elle international, and no error

in ezflow1 and ez4.0

perhaps it need some modif in the last version

Thursday 09 July 2009 10: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!

Thursday 09 July 2009 10: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.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from