• RSS 0.91
  • RSS 1.0
  • RSS 2.0
  • ATOM 0.3
  • OPML

Include external scripts

 the task 

Assuming we want to include an external script called myscript.php
There are currently the following possibilities (assuming you did install Moslate already), choose the one you prefer...

 A - use scriptlet 

In the first version we do this by using the {scriptlet}-tag...
1) Import the samples_export
2) Edit a content-item (assuming default configuration)
and write:
  1. {moslate} {scriptlet} include('myscript.php'); {/scriptlet} {/moslate}


 B - use jsp:include 

This time we go for a cleaner way by using jsp:include (defined by the JSTL)
1) Import logic_export
2) Edit a content-item (assuming default configuration)
and write:
  1. {moslate} {jsp:include page="/myscript.php"/} {/moslate}


 C - use c:import 

This is similiar to jsp:include, but it allows an URL instead. It is also possible to redirect the output to a Logic variable.
1) Import logic_export
2) Edit a content-item (assuming default configuration)
and write:
  1. {moslate} {c:import url="http://somehost/myscript.php"/} {/moslate}


 D - create moslate (mode:Eval as PHP) 

This time we reduce the code inside the content item:
1) Go to Moslate Categories and create a Category (or skip this and use an existing)
2) Go to Manage Moslate and click on New
3) For the name you may choose: includemyscript
4) In your template code write:
  1. include 'myscript.php';
5) Click on the Parameters-tab (the most to the right)
6) For mode choose: Eval as PHP
7) Edit the content item and write:
  1. {moslate} {includemyscript param1="value1" param2="value2"/} {/moslate}

This also demonstrates how to pass optional parameters to your newly created Moslates. Those parameters will be automatically available as local function variables (they are not global).

 E - create moslate (mode:Include PHP) 

This is very similiar to the above but uses another mode to include the script:
1) Go to Moslate Categories and create a Category (or skip this and use an existing)
2) Go to Manage Moslate and click on New
3) For the name you may choose: includemyscript2
4) In your template code write:
/pathtomambo/myscript.php
5) Click on the Parameters-tab (the most to the right)
6) For mode choose: Include PHP
7) Edit the content item and write:
  1. {moslate} {includemyscript2 param1="value1" param2="value2"/} {/moslate}

In this example an absolute path is used. If the path is relative, it will be relative to /components/com_moslate/templates.