Zcms:export

From GruppoZenit
Jump to: navigation, search

This tag can export the data in a template to particular format. Attributes that can be added to this tag are shown in the following table.

Attribute Description
type Defines the format in which the data is exported
  1. pdf
  2. zip
  3. text
  4. xls
  5. xml
template Defines the name of the page identifier that contains data to export.
  1. In case of pdf the the template will a xhtml page.
  2. In case of zip the template is a list of files(text feed) separated by '|'.
id Defines the id of the parameters given for the template.

The parameter value can be accessed using this "urlparam_id" from JavaScript or jquery

filename Defines the name in which the generated files is to be saved.
overwrite The value can be "true" or "false".if true it overwrites the generated file.
folder Defines the folder in which the file is to be generated.
 Ex: invoice
     invoice/2014/march
var Defines the variable in which the generated file path is to be saved.
ref Defines the id of the zcms:list tag for which the zip export has to be done.
message Defines message to be displayed in case of "zip", if no file is selected and download button is pressed.


An example of the export tag is given below.

<zcms:export type="pdf" id="result21" template="pdftemplate?filt=subdist&period=1">
   <a href="#"><img alt="pdf" src="img/pdf.png"/></a>
</zcms:export>


This tag can export the data that are stored inside page "pdftemplate" to pdf. The "pdftemplate" page is called by using specific parameters. Default given parameter is "filt=subdist&period=1", which value can be accessed from JavaScript or jquery by using the id "urlparam_ result21". The value of such parameter can be changed dynamically in the page using a script.


The stored values can also be used with use and session tags, as reported below.

<zcms:export type="pdf" id="result21" template="pdftemplate?filt=[zcms:use:filter]&period=[zcms:session:period]">
   <a href="#"><img alt="pdf" src="img/pdf.png"/></a>
</zcms:export>

Note: the template of the export tag supports only styles written inside the file.


Contents

Example: using export tag in a page for pdf

A complete example for the zcms:export is shown below, suggesting the template and its related Widgets used to export a pdf containing an exam result.


Xhtml page: downloadresult

The page contains the download link for the exam result - "click to download".

<zcms:pagestart />
   <head>
     <title>Download Result in pdf</title>
   </head>
   <body>
      <zcms:include widget="exam" type="download"/>
   </body>
<zcms:pageend />


Widget: exam_download

The PDF template and the parameters are defined in the export tag.

<zcms:store var="scid" value="$request[scid]"/>      
   <zcms:export type="pdf" template="template?id=[zcms:use:scid]">
      <a href="#" style="downloadlink">click to download</a>
   </zcms:export>


Xhtml page: template

The page serves as template for PDF. The styles of this page are defined inside the head tag.

<zcms:pagestart />
   <head>
      <style type="text/css">
         #idName{background:no-repeat #FFF url("[zcms:use:siteContext]img/page-logo.png"); height: 95px; width: 100%;}
      </style>
   </head>
   <body>
      <a id="idName" href=""></a>
      <div class="result_title">EXAM RESULT</div>
      <zcms:include widget="exam" type="result"/>
   </body>
<zcms:pageend />

Widget: exam_result

This widget is included inside the "template" page and generates the contents dynamically with the data from request.

<table>
   <tr>
      <th>Registration No.</th>
      <th>Result</th>
   </tr>

   <zcms:content name="result">
      <zcms:filter attribute="schoolid" value="$request[id]"/>
      <tr>
         <td><zcms:attribute name="regid"/></td>
         <td><zcms:attribute name="result"/></td>
      </tr>
   </zcms:content> 
</table>

Usage of zcms:export to generate the file automatically

The PDF can be generated automatically(without a click event) on the page load.In this case the parameters to the template should be passed using the zcms:param tag as shown in below example.Once the file is created the path of the will be returned and stored in the variable.

<zcms:store var="yvalue" value="900"/>
<zcms:store var="filenm" value="myfilename_second"/>
<zcms:store var="fileloc" value="invoice/2014/march"/>

<zcms:export type="pdf" var="filepath" filename="[zcms:use:filenm]" template="mytemplate" overwrite="true" folder="[zcms:use:fileloc]" >
                <zcms:param name="x" value="10"/>
                <zcms:param name="y" value="[zcms:use:yvalue]"/>
                <zcms:param name="z" value="20"/>
     </zcms:export>
<a href="#[zcms:use:appContext][zcms:use:filepath]">Click to download File</a>

Example: using export tag for creating zip on fly

Xhtml page: zippage

Once the page is previewed or published the zip will be created automatically and the path will be available in the given variable

<zcms:pagestart />
  <head>
        <zcms:pagehead />
        <title> ZIP on Fly </title>
  </head>
  <body>
    <zcms:include widget="zip" type="onfly"/>
  </body>
<zcms:pageend />


Widget: zip_onfly

<zcms:store var="filenm" value="myzip1"/>
<zcms:export type="zip" var="filepath" overwrite="true" filename="[zcms:use:filenm]" template="feed/filelist" folder="zipdata/march">
		<zcms:param name="x" value="10"/>
		<zcms:param name="y" value="[zcms:use:yvalue]"/>
		<zcms:param name="z" value="20"/>
</zcms:export>
<h1>File created on fly</h1>
<a href="#[zcms:use:appContext][zcms:use:filepath]">Cilck to download file</a>

Feed: filelist

The text feed provides the list of files to be zipped.each file in the feed will be separated by '|'

<zcms:feed type="text" delimiter="|">
  <zcms:include widget="response" type="feed2"/>
</zcms:feed>

Widget: response_feed2

  <zcms:content  name="ziptest">
     <zcms:attribute name="file"/>
  </zcms:content>
<zcms:out> img/aa.jpg</zcms:out>

Example: using export tag for creating zip using UI

Zip can be created for selected files.The file list can be created using the zcms:list and zcms:button tags. User created the zip by selecting the files from the list.

Example of generating zip files using UI

The below widget code can provide can generate the UI and the buttons

<h1>File Selection </h1>
<zcms:store var="filels" value="img/cp.jpg" />
<zcms:store var="myfile" value="zippeddata"/>
<zcms:store var="recid" value="61"/>
 
<zcms:list id="mylist"  class="mystyle" filesize="true">
  <zcms:content  name="ziptest">
    <zcms:file-list attribute="file"/>
  </zcms:content>
  <zcms:file-list name="[zcms:use:filels]"/>
  <zcms:file-list name="img/aa.jpg"/>
</zcms:list>
 

<div>
	<zcms:button class="tutti" text="Download Selected">
      <zcms:export type="zip" ref="mylist" filename="[zcms:use:myfile]" message="select some files"/>
    </zcms:button>
</div>

<div>
	<zcms:button download-all="true" class="tutti" text="Download all">
      <zcms:export type="zip" ref="mylist" filename="[zcms:use:myfile]"/>
    </zcms:button>
</div>

The output of the above example will be

Zcmszipexport.png

User can select the files and press "download selected" to download the zip.


Example: using export tag in a page for text

feed page: template

The page serves as template for text.

<zcms:feed type="text" delimiter="|">
<zcms:include widget="expfeed" type="expfeed">
</zcms:include>
</zcms:feed>

Widget: expfeed_expfeed

This widget is included inside the "template" page and generates the contents dynamically with the data from request.

<zcms:store var="name" value="$request[name]"/>
<zcms:use name="name"/>
<zcms:content name="studentdb" debug="false">
<zcms:attribute name="regno"/> <zcms:attribute name="name"/> 
</zcms:content>

xhthml:Create a text on click event

<zcms:export type="text" template="feed/feedpage1" >
<a href="#">link</a>
</zcms:export>

Usage of zcms:export to generate the text file automatically

<zcms:export type="text" template="feed/feedpage1" var="txtdata"  overwrite="true"/>
  <zcms:use name="txtdata"/>
    
    <a href="#[zcms:use:appContext][zcms:use:txtdata]">download</a>

Example: using export tag in a page for xls

xml page: template

The page serves as template for text.

<zcms:feed type="xml" node="table">
<zcms:include widget="getxml" type="getxml">
</zcms:include>
</zcms:feed

Widget: getxml_getxml

This widget is included inside the "template" page and generates the contents dynamically with the data from request.

<zcms:out node="helloo" type="ARRAY">

<zcms:out node="column">name</zcms:out>
<zcms:out node="column">skill</zcms:out>
<zcms:out node="column">age</zcms:out>

</zcms:out>
<zcms:content name="student">
<zcms:out node="row" type="ARRAY">
<zcms:attribute name="name"/>
<zcms:attribute name="skill"/>
<zcms:attribute name="age"/>

</zcms:out>
</zcms:content>

xhthml:Create a xls on click event

<zcms:export type="xls" template="feed/xmldata">
<a href="#">download</a>
</zcms:export>

Usage of zcms:export to generate the xls file automatically

 
<zcms:export type="xls" template="feed/xmldata" var="exceldata"  overwrite="true"/>
<zcms:use name="exceldata"/>
<a href="#[zcms:use:appContext][zcms:use:exceldata]">download</a>


Example: using export tag in a page for xml

The template for generation of xml is same as that of xls

xhthml:Create a xml on click event

<zcms:export type="xml" template="feed/xmldata">
<a href="#">download</a>
</zcms:export>

Usage of zcms:export to generate the xml file automatically

 
<zcms:export type="xml" template="feed/xmldata" var="xmldata"  overwrite="true"/>
<zcms:use name="xmldata"/>
<a href="#[zcms:use:appContext][zcms:use:exceldata]">download</a>

See also

Personal tools
Namespaces

Variants
Actions
Toolbox