Jump to content

Templates


Chewett

Recommended Posts

  • Root Admin

Copied From Murs initial Post (no code changed)

Templates

Function:

mds_template(template,data,return,columns,attributes);

Parameters:
template = template to use for each data displayed. Variables in this template should be noted as [[somename]] where 'somename' can be anything
data = can be an array with keys named like the strings enclosed in [[...]] in the template or a multidimensional array for more records. Such an array has each of its items as an array with values
return = if its true, function will return the string so it can be used in the script, if its false, it will display the result directly.
columns = for multidimensional arrays, this parameter tells on how many columns they should be displayed. If its false or 1 the records will be displayed one per row. It has no use if the data array does not contain multiple records.
attributes = when displaying multiple records, they get organized in a table. The attributes parameter can contain a string to be placed inside the <td ...> tag of each cell. This could be a style an attribute but also javascript or anything that is html valid.

You can use bits of content as templates with variables.
@content[1] is the content after the first content separator
lets say for this example template code contains:

[php]<b>[[name]]</b><br>[[rowinfo]]<br>Details: [[more]][/php]


Script to use this template:

[php]//make sure @tpl its empty
@tpl = array(); [php]<b>[[name]]</b><br>[[rowinfo]]<br>Details: [[more]]

//do something 20 times
for(@va=0;@va<20;@va++){
@tpl[@va]['name'] = "Record {@vk}";
@tpl[@va]['rowinfo'] = "Row {@vk} has value".@vv;
@tpl[@va]['more'] = "more values ...";
}

//call template function
mds_template(@content[1],@tpl,true,3,'style="border:1px solid"');[/php]


This will display the content in @tpl, on 3 columns, each time parsing the template in @content[1]. The style indicated in the last parameter will be used on each of the 20 table cells created.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Forum Statistics

    17.5k
    Total Topics
    182.5k
    Total Posts
  • Recently Browsing

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...