Latest News: (loading..)
Harald Ponce de Leon

Template Engine Functionality Proposal

71 posts in this topic

Hi All..

 

This is a proposal for adding actual template engine functionality into osCommerce Online Merchant v3.0 to remove PHP code from the content pages.

 

The proposal is shown through the development of our new website powered by the osCommerce Online Merchant v3.0 framework. The source code to our new website is published as Open Source (BSD license) however it will not be part of osCommerce Online Merchant v3.0 as it is obviously not a general purpose application. As soon as the template engine functionality is finalized, it will be added to the v3.0 framework to not only implement it to the Admin, Setup, and Shop sites, but to also kickstart the initiative of adding a general purpose CMS Site to osCommerce Online Merchant v3.0.

 

The template engine functionality is currently aimed at developers. An Admin Application will be needed for users to be able to edit page content and see which template engine functionality is available to them.

 

The source code of our website and the initial template engine functionality is available at:

 

https://github.com/haraldpdl/oscommerce_website

 

Instructions for setting up the website is available at the github repository. It is currently only the front page to demonstrate the template engine functionality.

 

The idea behind the template engine functionality is to NOT add logic into content pages where users and developers need to learn yet another language for conditions or loops - PHP does this just fine.

 

The idea is to "widgetize" content pages through the use of simple tags used in addition to HTML. Simple processing is taken care of with Tags and more powerful and modular processing is taken care of with Widgets. Both Tags and Widgets are called in the following format, similar to bbcode:

 

{tag}value{tag}

 

No closing {/tag} is used - only matching {tag}{tag} pairs are processed.

 

The following tags are available:

  • import - include html content from another file
  • lang - get language definition
  • link - produce a url
  • publiclink - produce a url to a public asset
  • value - get the value of a variable
  • widget - process widget

Each Tag is a module. The template processing does not search for a hardcoded list of tags to process, but searches for {[tag-name]}string{[same-tag-name}] and processes "string" with the Tag if the module is available.

 

It's possible to nest Tags and by default the same processing is also executed on the output of the Tag, for example using {link}Index{link} is possible in a language definition. This can be disabled at the Tag level if it is not required.

 

It is up to each Tag to process the string value as it requires. Some Tags may need arguments to be passed - both link and publiclink Tags use | as a separator in the string value to process arguments, example {link}Index|Shop{link} would create a link to the Shop Index page, not to the Index page of the current Site.

 

For cases where more complex arguments are needed, a variable can be pre-set at the Site level to make it available to all of its Applications, or at the Application level specific for that Application. This is contained in $OSCOM_Template->_values[] and the value can be retrieved with the {value} Tag.

 

Widgets are used where coding logic is needed or to add independent blocks to a page. Each Widget has it's own language definition file and can be added to any page.

 

Please take a look at the source and provide feedback on the direction this is going in. Caching will need to be looked into.

 

Thanks!

Edited by Harald Ponce de Leon

Share this post


Link to post
Share on other sites

Hi All..

 

I just pushed out some code to the oscommerce_website repository that adds an Admin Sites Application to create skeleton Sites and Applications through the Admin Dashboard. The initial commit is pretty raw/alpha and focuses on creating new Applications - more work is definitely needed.

 

This will help developers code Sites and Applications faster, and will ultimately help users edit the styling and content of their pages. This uses the new template engine functionality which is why it is committed to the oscommerce_website repository and not yet to the main repo.

 

Further information will be provided as more code gets pushed out.

 

Kind regards,

Share this post


Link to post
Share on other sites

Hi All..

 

I just pushed out updates to oscommerce_website that replace the usage of Semantic.gs with Twitter Bootstrap. This will also be used for new Sites created through the Admin Dashboard (this feature will be pushed out in the coming days).

 

For those keeping up to date with oscommerce_website, a link to the public/external/bootstrap is required.

 

Kind regards,

Share this post


Link to post
Share on other sites

Hi All..

 

The feature to create new Sites via the Admin Dashboard has just been pushed to the oscommerce_website repo. It's now possible to create skeleton Sites and Applications via the Admin Dashboard!

 

This is still pretty raw and focused for developers to use, but does provide great opportunities for awesome user-end features in managing a Site and its Applications.

 

The code will be pushed to the main repo as soon as the new template engine functionality is moved over as the new Site and Application creation feature creates content pages utilizing the template engine functionality.

 

Kind regards,

Share this post


Link to post
Share on other sites

Hi All..

 

Here's a screenshot of how a new skeleton Site looks like:

 

post-2-0-63734300-1328830274_thumb.png

 

One of the first dynamic elements for a user-end feature is to have a navigation bar linking to Applications and external links.

 

Kind regards,

Share this post


Link to post
Share on other sites

Hi All..

 

An installation of oscommerce_website is available at:

 

http://new.oscommerce.com

 

The pages are currently placeholders and links may not work. This will be kept up to date with what is pushed to the Github repo. This is the first public testing of the template engine functionality and the first peak of our new website :)

 

Kind regards,

Edited by Harald Ponce de Leon

Share this post


Link to post
Share on other sites

Hi All..

 

I just created a new branch in my repo called "template" where the template engine functionality, Tags, and Widgets have been merged to. (Please note the "template" branch is a child of the "master" branch, not the "cfg" branch)

 

The Login and Configuration Admin Applications have been updated to use the proposed template engine functionality, meaning its content pages contain absolutely no PHP code.

 

Two logic Tags have been introduced:

  • loop; loop over an array (defined as a parameter) and replace #var# in the block with its value
  • iftrue; output the block if its parameter value is true (similarly an iffalse tag can also be created)

The parameters for these tags are defined as:

 

{loop var}
<p>#key#</p>
{loop}

{iftrue var}
<p>It's true!</p>
{iftrue}

 

The API has slightly changed from what was introduced in the oscommerce_website repo which will soon be updated with the new changes.

 

Kind regards,

Edited by Harald Ponce de Leon

Share this post


Link to post
Share on other sites

Hi Harald,

i'll take a look during this weekend

 

I have a dream ... i hope, a day, Samantha Fox will be an Array. and maybe, a new getContent method() could surrendering to the spirit of the night (w00t)

Share this post


Link to post
Share on other sites

(Please note the "template" branch is a child of the "master" branch, not the "cfg" branch)

 

ok, in this case, i can't test it with kendo UI.

I'm only developping with 3.0.4.(need to implement services)

fragmentation is dangerous. :x

Edited by foxp2

Share this post


Link to post
Share on other sites

Hi All..

 

The Admin template has been updated to remove the PHP code and use the Template Tags. There is a limitation here I'd like to address that can be shown perfectly with this commit:

 

https://github.com/haraldpdl/oscommerce/commit/93b73f04e70ed5bff1ec0f6df28d32297a91e5b3

 

As can be seen, the values for the page content are defined in the Site Controller - these are available to all Applications. Application specific values are defined in the Application Controller. So far so good, however it's not a flexible/dynamic solution at all:

 

1) Values are hardcoded in Controllers.

2) Imagine a GUI for editing template files, it will be cumbersome to parse files to return a list of values available to use

 

I think it would be much better to move these values into modules and have the {value} Tag call the specified module. This helps immensely with #2 as a list of available values can easily be generated (Core values and Custom/Add-On values).

 

Now to think about where these modules should exist ....

Share this post


Link to post
Share on other sites

hi Harald,

after repititive and too much static codes, you create a complicated overlapping between application layers.

it leaves me speechless. :x

Share this post


Link to post
Share on other sites

Hi Laurent..

 

Can you please describe your thoughts further and point out what is being repetitive and overlapped?

 

Thanks,

Share this post


Link to post
Share on other sites

Hi Laurent..

 

Can you please describe your thoughts further and point out what is being repetitive and overlapped?

 

Thanks,

 

No.

I will wait for your implementation of this template engine and a real dynamic binding between Views, Models and Controllers.

For now, IMO, your code becomes increasingly unreadable.

i'm sorry but I am not convinced

Edited by foxp2

Share this post


Link to post
Share on other sites

Hi Laurent..

 

The architecture knows how it all comes together ;)

 

After the values have been moved to modules you will see how flexible it will become.

 

The only thing I'm not happy with at the moment is how parameters are passed to Tags - I will bring this up for discussion soon to see how it can be improved.

 

Kind regards,

Share this post


Link to post
Share on other sites

Hi Harald,

osCommerce framework is really fantastic.

Our framework has really qualities.

I have a full respect for your work.

 

but i think, sometimes, you forget a thing : the combination between user experience and user interface.

Let us make sure we'll have the better tomorrow.

Share this post


Link to post
Share on other sites

Hi All..

 

The values made available to the template have now been abstracted to modules. This can be seen with the following commit:

 

https://github.com/haraldpdl/oscommerce/compare/93b73f04e7...9b3236e192

 

The {value} Template Tag has been updated to retrieve the value in the following order:

  1. Load the value module at the Application level (if module exists), else
  2. Load the value module at the Site level (if module exists), else
  3. Load the value internally if no module exists

This improves performance of loading modular values on demand and improves flexibility where values can be defined without editing core source code files.

 

Laurent pointed out that there is a lot of static code in the framework. YES! Not all classes must be instantiated into objects - those that do not need to work as objects are kept static to improve performance and memory. We are also moving in the direction of strictly checking loadable modules against a base abstract class, eg:

 

if ( class_exists($module) && is_subclass_of($module, 'ModuleAbstract') )

 

This strengthens the API and makes sure the modules contain the minimum set of needed functionality.

 

The framework has 2 main namespace levels: Core and Custom. A third level will be introduced for templates where additional templates can override content based on the default template. This existed in v3.0Alpha5 but was removed during the migration to the new framework. Having the PHP code removed from the template content (Views) helps here immensely.

 

Laurent is working on a KendoUI template for the Admin Site. This will not be part of the core however it will make for an awesome add-on that shows the flexibility of the core framework.

 

Tim (who works for Nick Weisser) previously worked on a jQuery Mobile template for the Shop Site. Again, the work here in whole helps create optimized templates without duplication of core PHP code. YES! There will be duplication of HTML code (Views) specific for each template as CSS is not the answer to everything.

 

Kind regards,

Edited by Harald Ponce de Leon

Share this post


Link to post
Share on other sites

clone public/sites/Admin/templates/oscom -> public/sites/Admin/templates/Sail :

 

Share this post


Link to post
Share on other sites

Hi harald,

Could you modify the Access class to account for the new structure in Custom/Site/' . OSCOM::getSite() . '/Template ?

thanks

^_^

Share this post


Link to post
Share on other sites

Hi harald,

i really need your help.

i have a serious problem with access class.

i need to override this class (but i feel it's not possible with your new structure)

why ? it is really simple : in static function getLevels, we have : $_SESSION['Admin']['id'] harcoded, but in my scenario (with a new Site PublicAdmin, it doesn't work, because the session should be $_SESSION['PublicAdmin']['id'])

so, how to override this class in Custom folder and the correct Namespace ?

 

i hope, like Rick, you never gonna give me up ... :'(

Share this post


Link to post
Share on other sites

Meanwhile, i've changed this method with this code :

   public static function getLevels($group = null) {
  $access = array();
  if ( isset($_SESSION['Admin']['id']) && isset($_SESSION['Admin']['access']) ) {
    foreach ( $_SESSION['Admin']['access'] as $module => $data ) {
	  if ( ($data['linkable'] === true) && (empty($group) || ($group == $data['group'])) ) {
	    if ( !isset($access[$data['group']][$data['sort_order']]) ) {
		  $access[$data['group']][$data['sort_order']] = $data;
	    } else {
		  $access[$data['group']][] = $data;
	    }
	  }
    }
    ksort($access);
    foreach ( $access as $group => $modules ) {
	  ksort($access[$group]);
    }
  }elseif(  isset($_SESSION['PublicAdmin']['id']) && isset($_SESSION['PublicAdmin']['access']) )  {
    foreach ( $_SESSION['PublicAdmin']['access'] as $module => $data ) {
	  if ( ($data['linkable'] === true) && (empty($group) || ($group == $data['group'])) ) {
	    if ( !isset($access[$data['group']][$data['sort_order']]) ) {
		  $access[$data['group']][$data['sort_order']] = $data;
	    } else {
		  $access[$data['group']][] = $data;
	    }
	  }
    }
    ksort($access);
    foreach ( $access as $group => $modules ) {
	  ksort($access[$group]);
    }	   
  }
  return $access;
   }

 

this code is functionnal (now, i can get a Public Admin Site and Private Admin Site, each have their own namespace/custom folder/template/Session/Database) but I'm not really satisfy because this class is in the Core

I'm waiting for a response ...

Share this post


Link to post
Share on other sites

Hi harald,

 

i get an issue :

 

PHP Fatal error: Namespace declaration statement has to be the very first statement in the script in \osCommerce\OM\Core\Site\Admin\Controller.php on line 9

Edited by foxp2

Share this post


Link to post
Share on other sites

lol, i've found ... have a space before the firts <?php tag ...

i confirm, it works like a charm.

thanks for your help.

Kind regards,

Share this post


Link to post
Share on other sites

Hi harald,

 

there are problems with your template engine ...

before this new structure, to customize a core source file was very easy.

example (for Dashboard) : https://github.com/foxp2/French-Rebellion-Project/tree/master/osCommerce/OM/Custom/Site/Admin/Application/Dashboard

 

but if i change protected $_default_template in \osCommerce\OM\Core\Site\Admin\Template.php with 'Sail', your template engine doesn't work (normal, Custom Core File having priority in accordance with loading) :x

 

now, if i move my Custom/Site/Admin -> Custom/Site/Admin/Template/kendo/ ... only \osCommerce\OM\Custom\Site\Admin\Template\kendo\Application\Dashboard\pages\main.php ... :wacko:

 

what you think about it ?

have you really tested your framework in differents scenarios ?

 

Perhaps you could clarify that for me.

 

Thanks.

 

Kind regards.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now