[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.