Personal tools
Views

User Handbook/Admin Panel/Tags/content dump

From CMSMS

This page in: English - Deutsch - Español - Français - Italiano - Lietuvių - Nederlands - Norsk - Polski - Русский - Svenska - Tiếng việt - عربي

Tag Content_Dump

Contents

Introduction

For Version 0.7:

There is no required parameter, if no parameter is set, all sites content will be shown. The default usage of the tag will not compile any smarty nor will it filter it out.

Just placing {content_dump} will already do a lot for you as you can make a lot with the output in conjunction with smarty. However, just placing the tag into a page/template won’t show anything. The tag will run and you’ll get to know if all works out fine - when you see nothing.

Now add some smarty to the soup and you’ll start to see something.

Ok, the simplest method to get to the data is by addressing the class array directly. Something like {$dump[0]->content->title} would give you the first pages title.

So having {content_dump} {$dump[0]->content->title} in your template/content will output the first sites pages’ title (which will most likely be “home”).

Basics

Yes, “fancy” I hear you say. But do something like this in your template and see all page titles:

 {content_dump}
  {foreach from=$dump item=dump}
  {$dump->content->title}
 {/foreach}

But title isn’t the only thing you can use. Depending on what parameters you use, you can get information about the parent page or about the creator and last editor of a page. {content_dump this_only=$content_id users=true} allows you to access the username, first and last name as well as the e-Mail and ID of the mentioned users.

Placing Written by: {$dump[0]->created->by->firstname} {$dump[0]->created->by->firstname} into your regular page template, automatically posts the articles original author into your page.

So you see, you can get extra data from and for very specific elements if you want to.

So, let’s do something more sophisticated. How about getting all titles of the pages that are below a specific page. Then do something like this:

 {content_dump start_id=”17”}

Hey, but we didn’t want the startpage to be included! Just add exclude=”17” to your tag and it’s gone. Oh, page 25 shall also be excluded? No problem, let’s make it exclude=”17,25”. And getting the creation date would be nice. No Problem. At the end, the tag call would look like this:

 {content_dump start_id=”17” exclude=”17,25”}
 {foreach from=$dump item=dump}
   {$dump->data->title}
   {$dump->created->date}
 {/foreach}

You get too many results? Just want to see 5? Let’s add limit_count=5 to the tag. And we are done. If we want to see the second 5 entries, we just shift the start position with limit_start=6.

 {content_dump start_id=”17” exclude=”17,25” limit_start=6 limit_count=5}

Want to see the latest pages? Try the sorting mechanics. You can sort by 9 options (check the parameters description). To display the newest 10 entries of the site area below page 17 we can do something like this:

 {content_dump start_id=”17” exclude=”17” limit_count=10 first_sort=”created” first_sort_order=”down”}

Now let’s add links and content to our entries and give it some style. We do not need to change anything with the tag. We just wrap some html (XML, JS or CSS or whatever you are thinking of) around the smarty in the content/template and that’s it.

 {content_dump start_id=”17” exclude=”17,25” block_name=”summary”}
 <h1>Product overview:</h1>
  {foreach from=$dump item=dump}
   <h2>{$dump->content->title}</h2>
    <span class=”date”>{$dump->created->date}</span>
    {$dump->content_>data}
   <a href=”{$dump->content->alias}.htm”>See: {$dump->content->title}</a>
  {/foreach}

You might want to get specific content blocks from a page, just list the blog names with the parameters extensions and you can have them.

 {content_dump start_id=”17” exclude=”17,25” extensions="summary,image,some_other_block"}
 

To access the additional content elements, use something like:

 {$dump[0]->extensions->some_other_block->data}
 {$dump[0]->extensions->image->data}
 {$dump[0]->extensions->summary->data} 

Available data elements

Generally, you can access these elements:

 $dump [ n ] -> item = Counter for items in current list (integer)
 
 $dump [ n ] -> content -> id
 $dump [ n ] -> content -> alias
 $dump [ n ] -> content -> title
 $dump [ n ] -> content -> show
 $dump [ n ] -> content -> active
 $dump [ n ] -> content -> data
 
 $dump [ n ] -> parents -> id
 $dump [ n ] -> parents -> alias
 $dump [ n ] -> parents -> title
 
 $dump [ n ] -> created -> date
 $dump [ n ] -> created -> by -> username
 $dump [ n ] -> created -> by -> last_name
 $dump [ n ] -> created -> by -> first_name
 $dump [ n ] -> created -> by -> email
 
 $dump [ n ] -> modified -> date
 $dump [ n ] -> modified -> by -> username
 $dump [ n ] -> modified -> by -> last_name
 $dump [ n ] -> modified -> by -> first_name
 $dump [ n ] -> modified -> by -> email
 
 $dump [ n ] -> extension (will be 1 if any extension contains something, default: 0)

And for each extension you have named, you will get an equally named class element below $dump [ n ] -> extensions (note the "s" at the end).

e.g.

 $dump [ n ] -> extensions -> summary -> data
 $dump [ n ] -> extensions -> summary -> length

Usable Parameters (all optional)

Basic Parameters for shaping the collection


Selecting the main content-block

block_name can be used to define the content block you want to use as the $dump[n]->content->data element. Per default, it will be "content_en", the page standard content block. If the block you want to show is {content block="summary"} in your source page's template, you would call it like in the following example:

 {content_dump block_name="summary"}
Where should the dump begin (root ID of collection)?

start_id can be used to define a starting point for your content collection. If not specified, it will begin with id "-1" and thus include all matching pages from all pages. A nice trick to use the tag in several pages based on the same template and limit the tag to this site area is to set start_id=$content_id. This way, you use the viewed page's id as the initial page and ignore all other content folders.

 {content_dump start_id=16}
Just show the data of a specific element

this_only is a parameter that will limit the result to this specific ID.

 {content_dump this_only=55}
How can I paginate content_dump?

page can be used to generate a page based view. Value is page number. It will basically move the view you have on the results by the number of items specified in limit_count. It alters the limit_start by adding limit_count to it, each time an increasing page is selected. Let's say you have limit_start=0 and limit_count=5, page=2 will alter limit_start to be 6.

Usage of this parameter will provide some extra smarty data elements. $pager_info->current, $pager_info->max and $pager_info->size. Representing the currently selected page, the maximum page available and the page size. Use smarty and this data to build easy and complex pagers alike.

 {content_dump limit_count=5 page=2}
Show also inactive pages or only inactive pages.

active can be used to control how the ACTIVE flag of pages should be interpreted. "force" shows all pages regardless of status. "active" show active pages only (default). "inactive" show inactive pages only.

 {content_dump active="force"}
Show in menu - what about that?

show_in_menu can be used to control how the SHOW_in_menu flag of pages should be interpreted. "force" shows all pages regardless of status. "show" show pages set to "Show in Menu" only (default). "hidden" show pages that are set to "Don't Show in Menu" only.

 {content_dump show_in_menu="hidden"}
 

Filter, Search and Prefix Handling

Filter for specific content (e.g. check if data fields contain the word "world")

filter can be used to limit the results to entries which contain specific words or phrases or to exlude such items. Use boolean logic. e.g. filter="-hello" to exclude items that contain the word "hello" in any of their content->data or extension->itemname->data elements or filter="world" to limit the results to those items that contain the word "world" in any of their data elements.

 {content_dump filter="world -hello"} 

Use this MySQL Syntact to add FULLTEXT index to your content_props table:

Attention: To use this specific feature, you have alter your content_props table in the DB manually. If you have no clue what you are doing there and what that means, you might want to consider not to use this specific feature.

 ALTER cms_content_props ADD FULLTEXT (content)
Exclude or limit (filter) the output to pages with matching alias prefix

prefix can be used to state the prefix or prefixes that should be considered for exluding from the collection or that should be the only pages in the collection. Several prefix are seperated by comma. E.g. {content_dump prefix="private_,special_"}

 {content_dump prefix="prefix1,prefix2"} 
How should the prefix or list of prefix(es) be handled?

prefix_mode Prefix-mode is used to controll the handling of the prefix(es). "force", "neutral" and "hide" are the available values. Standard mode is neutral that will disregard any available prefix. Forced mode only shows pages with one of the stated prefixes. Hide will exlude pages with the prefix from the items returned.

 {content_dump prefix_mode="hide"} 
How can I limit the output to specific hierarchy levels (e.g. depth) ?

depth is used to control the what hierarchy levels should be considered for output. It takes two integer values seperated by comma (e.g. depth="-1,3"}. The first value defines the starting hierarchy. -1 = start with content_dump, n = start with specific hierarchy level [0 and 1 both return first level].

The second value defines the number of additional levels added to the collection. 0 = no depth, siblings of page specified with first depth value are returned (if not excluded otherwise). n = number of additional level relative to the level specified with first depth value.

Both values must be used!

 {content_dump depth="-1,3"} 

Specifically exclude items from the collection

Skip the first X items (offset).

limit_start will allow you to do that. State the number of the item you would like your output to begin with. Default is 0

 {content_dump limit_start=5}
Limit the output to a specific number of items.

limit_count can be used to limit the output to a specific number. In combination with page, it will define the size of a page.

 {content_dump limit_count=10}
Exclude single items from the list

exclude allows you to remove specific pages from the results. It takes any number of content IDs seperated by comma. Especially when forcing content_dump to compile smarty in found content-blocks, you can use this tag to break endless recursions or for any other reason where you want specific pages not to appear.

 {content_dump exclude="13,23,53,12,32"}


Add more data to the item - Request more item info

Get more information about parent pages

parents can be used to request more information about the parent pages (alias and title). Possible values are true or false. Using this parameters allows you to use the data element $dump[n]->parents->alias or $dump[n]->parents->title. The data element $dump[n]->parents->id will be provided in any case. Per default it is deactivated.

 {content_dump parents=true}
Get more information about users that wrote/edited the content

users can be used to request more information about the users who last edited and created the content. Possible values are true or false. Per default $dump[n]->created->by and $dump[n]->modified->by will only return the user ID. If set to true, the mentioned class elements will be expanded by detailed user info (first-, last- and user name).

 {content_dump users=true}
I want to use more content-blocks from the single pages

extensions is your choice then. It takes a comma seperated list of content_blocks. If any of them (for an item) features content, $dump[n]->extension will be "1", other wise it will be "0" (default). This can be used to check for availability of "more" data. Each content_block will be added as a class below $dump[n]->extensions. E.g. {content block="more_text"} will be available as $dump[n]->extensions->more_text->data together with $dump[n]->extensions->more_text->length. Ideally, your content block names do not feature special charcacters and not " " or "-", use "_" instead.

 {content_dump extensions="summary,image,other_block_name"}
 

Process data from items

Change the date format to someting else

dateformat can be used to format the date output of content_dump. Check http://de.php.net/strftime for more ifo on the date format options. Per default it is set to "%A, %e %B %Y" (e.g. Sat, 20 September 2008). It is used for the two time stamps $dump[n]->created->date and $dump[n]->modified->date that are always returned with each item.

 {content_dump dateformat="%A, %e %B %Y"}
I want smarty from content-fields to be compiled, or removed

do_smarty controls how smarty data that may be retrieved should be handled. There are three options "compile, neutral and strip". "compile" compiles smarty data in in the pages found. "neutral" prints out the smarty code as regular text and is the default setting. "strip" deletes all smarty code from your page (well, everything between { and }).

However, be carefull not to construct a query that would have to compile itself, this will result in an out of memory error due to endless recursion. If you use this tag only once with the compile parameter in your site, no problem, it prevents itself from being rendered. But if you have another occurences of this tag that would include the page that is calling the currently processed tag with compile="true", you should exclude all of these pages (content dump does not check for the compile parameter of other occurences of the tag).

If that called tag would feature other content blocks.. then again all would work nice. Just do not construct something with content_dump that is somewhere in the chain of events compiling itself.

 {content_dump do_smarty="compile"}
Remove HTML from content elements so I can safely truncate the data

html is a parameter that allows you to remove any HTML, JavaScript and CSS from a content-block. "strip" and "neutral" are the available options. "Neutral" will display the content as it is (after processing do_smarty settings) and is the default setting. "Strip" will remove the mentioned elements.

 {content_dump html="neutral"}
 

Sort items

Primary sorting of data elements

first_sort sorts the found content by one of the following values: id, title, created, modified, owner, hierarchy (default), lasteditor, active, show (show in menu). For time based (like newest contents) use created, for last updated lists use modified (both need to be reversed with sort_order). Hint: Sorting by owner or lasteditor takes place by ID, not name!

 {content_dump first_sort="owner"}
Set the direction of primary sorting

first_sort_order can be used to reverse the sorting filter. "up" and "down" are the available options, whereas "up" (A before B or yesterday before today) is the default direction.

 {content_dump first_sort_order="up"}
Secondary sorting of data elements

second_sort sorts the found content by one of the following values: id, title, created, modified, owner, hierarchy, lasteditor, active, show (show in menu). For time based (like newest contents) use created, for last updated lists use modified (both need to be reversed with sort_order). Hint: Sorting by owner or lasteditor takes place by ID, not name!

 {content_dump first_sort="owner"}
Set the direction of secondary sorting

second_sort_order can be used to reverse the sorting filter. "up" and "down" are the available options, whereas "up" (A before B or yesterday before today) is the default direction.

 {content_dump first_sort_order="up"} 
 

Usefull Smarty Snippets for content_dump

Prepare template for paging

{assign var=page_call value=$smarty.get.show_page} {if $page_call == ""}{assign var=page_call value=1}{/if}

This will listen for URL parameter called show_page and its value. If no parameter found, create is and assign value 1. Use $page_call as the value of the page parameter {...page=$page_call...}

"newer" "older" pager

 {if $page_call > 1 }
  <a href="blog.htm?show_page={$pager_info->current-1}">newer articles</a>
 {/if}
 
 {if $pager_info->max > $page_call}
  <a href="blog.htm?show_page={$pager_info->current+1}">older articles</a>
 {/if}

Page number list pager

 {section name="i" start=1 loop=$pager_info->max+1 step=1}
  <a href="blog.htm?show_page={$smarty.section.i.index}">{$smarty.section.i.index}</a>
 {/section}

Walk through all available elements

 {content_dump ... }
 {foreach from=$dump item=dump}
  {$dump->content->data}
 {/foreach}

Display read more link

 {content_dump ... }
 {foreach from=$dump item=dump}
  {if $dump->extension == 1}
   <a href="{$dump->content->alias}.htm">read more</a>
  {/if}
 {/foreach}

Display basic blog style summary listing of pages below

Remove dots "." from markup - used here to prevent HTML from being interpreted.

 {content_dump block_name="page_summary" start_id=$content_id}
 {foreach from=$dump item=dump }
 <.div class="blog_entry">
  <.h3>{$dump->content->title}<./h3>
  <.span class="date">{$dump->created->date}<./span>
  <.p>{$dump->content->data}<.br />
  {cms_selflink page=$dump->content->alias text="See: {$dump->content->title}"}
  <./p>
 <./div>
 {/foreach}

This page in: English - Deutsch - Español - Français - Italiano - Lietuvių - Nederlands - Norsk - Polski - Русский - Svenska - Tiếng Việt - عربي