Page 1 of 1

Number of {conent block} set in the page options???

Posted: Wed Feb 05, 2014 6:19 pm
by booka
Hello there!

I had tried to add an option to set content block amount at the page options, but it seems parcer wouldn't allow me to do what I want. How this could be done?

Code: Select all

<!-- TEMPLATE BLOCKS --> 
{capture assign="magpagenumber"}{content block="magpagenumber" oneline="true" label="Number of magazine pages" page_tab='Header' wysiwyg='false'}{/capture}
<!-- END TEMPLATE BLOCKS -->

{if $magpagenumber > 0}
{section name=i loop=$magpagenumber} 
    {if $smarty.section.i.index is div by 2}
        <div class="mag-page-even">
    {else}
        <div class="mag-page-odd">
    {/if}
    {$i == $smarty.section.i.iteration} 
    {content block="{$i} page"}
    </div>
{/section} 
{/if}
It creates enough divs but only 1 content block.

Re: Number of {conent block} set in the page options???

Posted: Wed Feb 05, 2014 6:41 pm
by Jo Morg
That simply won't work. Page blocks can't (afaik) be set dynamically from the content editor. These must be set statically on the chosen template and the editor will parse it once: when the template for the current page is set.

Re: Number of {conent block} set in the page options???

Posted: Wed Feb 05, 2014 7:43 pm
by booka
Jo Morg wrote:That simply won't work. Page blocks can't (afaik) be set dynamically from the content editor. These must be set statically on the chosen template and the editor will parse it once: when the template for the current page is set.
The main difficult is to set few {content block="id"} with id increment.

Re: Number of {conent block} set in the page options???

Posted: Wed Feb 05, 2014 8:40 pm
by Jo Morg
How many are "few"?
There are a few approaches possible, two being pretty obvious to me:
  1. if you know the maximum number of blocks that will ever be used (assuming a reasonable number) then use:

    Code: Select all

    {content block="page 1" assign="one"}
    {content block="page 2" assign="two"}
    {* etc *}
     
    and then where you want them to show:

    Code: Select all

    {if isset($one)}
     <div class="mag-page-odd">
    {$one}
    </div>
    {if}
    {if isset($two)}
     <div class="mag-page-even">
    {$two}
    </div>
    {if}
    {* etc *}
  2. Create a number of templates with different number of blocks (worse for the designer/developer but better for the editor). Not a reasonable choice for a huge number of pages

However I don't see why would you even want to do this: the best way to publish articles is through other modules, like:
  • - News (core module);
  • - Blog;
  • - ListIt2;
In the case you need pagination and the module doesn't provide it you can resort to a smarty block plugin that divides the content in manageable pages (IIRC it is called precisely Pagination but you would have to search, I don't use it for ages). Other possibilities exist with javascrip and JQuery, for instance.