Jump to content



Latest News: (loading..)

- - - - -

Get a custom {value} Template Tag

branch template

  • Please log in to reply
4 replies to this topic

#1   foxp2

foxp2

    strong as a Twig

  • Members
  • 303 posts
  • Real Name:Laurent
  • Gender:Male
  • Location:France

Posted 19 August 2012 - 09:44 AM

View PostHarald Ponce de Leon, on 03 March 2012 - 11:27 AM, said:

The {value} Template Tag has been updated to retrieve the value in the following order:
  • Load the value module at the Application level (if module exists), else
  • Load the value module at the Site level (if module exists), else
  • Load the value internally if no module exists

.../...

4. to create your own {value} Template Tag :
change this class with :
file : \osCommerce\OM\Core\Template\Tag\value.php
<?php
/**
* osCommerce Online Merchant
*
* @[member='copyright'] Copyright (c) 2012 osCommerce; http://www.oscommerce.com
* @[member='copyright'] Copyright (c) 2012 FoxP2;
* @[member='licensed2kill'] BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
  namespace osCommerce\OM\Core\Template\Tag;
  use osCommerce\OM\Core\OSCOM;
  use osCommerce\OM\Core\Registry;
  class value extends \osCommerce\OM\Core\Template\TagAbstract {
	static protected $_parse_result = false;
	static public function execute($string) {
	  $OSCOM_Template = Registry::get('Template');
	  if ( !$OSCOM_Template->valueExists($string) ) {
		// foxp2 : override {value] tag or call {value} tag in custom directory
		if ( class_exists('osCommerce\\OM\\Custom\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller') && is_subclass_of('osCommerce\\OM\\Custom\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ){
		  call_user_func(array('osCommerce\\OM\\Custom\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'initialize'));
		} elseif ( class_exists('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $string . '\\Controller') && is_subclass_of('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ) {
		  call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'initialize'));
		} elseif ( class_exists('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller') && is_subclass_of('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ) {
		  call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'initialize'));
		}	  
	  }
	  return $OSCOM_Template->getValue($string);
	}
  }
?>

ok, now i can create my own nav apps menu like :
\osCommerce\OM\Custom\Site\Admin\Module\Template\Value\apps_links_responsive\Controller.php :
<?php
/**
* osCommerce Online Merchant
*
* @[member='copyright'] Copyright (c) 2012 osCommerce; http://www.oscommerce.com
* @[member='copyright'] Copyright (c) 2012 FoxP2
* @[member='licensed2kill'] BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
  namespace osCommerce\OM\Core\Site\Admin\Module\Template\Value\apps_links_responsive;
  use osCommerce\OM\Core\Access;
  use osCommerce\OM\Core\OSCOM;
  use osCommerce\OM\Core\Registry;
  class Controller extends \osCommerce\OM\Core\Template\ValueAbstract {
	static public function execute() {
	  $OSCOM_Template = Registry::get('Template');
	  $apps_links_responsive = '';
	  if ( isset($_SESSION[OSCOM::getSite()]['id']) ) {
		  $apps_links_responsive .= '<div class="subnavbar">';
		  $apps_links_responsive .= '		<div class="subnavbar-inner">';
		  $apps_links_responsive .= '		  <div class="container">';
		  $apps_links_responsive .= '			<ul class="mainnav">';
		  // dashboard link
		  $apps_links_responsive .= '			  <li>';
		  $apps_links_responsive .= '			  <a href=' . OSCOM::getLink(null, OSCOM::getDefaultSiteApplication()) . '><i class="icon-dashboard"></i><span>Dashboard</span></a>';
		  $apps_links_responsive .= '			  </li>';
		  // apps menu		
		  foreach ( Access::getLevels() as $group => $links ) {		
		  $application = current($links);	  
		  $apps_links_responsive .= '			  <li class="dropdown">';
		  $apps_links_responsive .= '			  <a href="#" class="dropdown-toggle" data-toggle="dropdown">';
		  $apps_links_responsive .= '			  <i class=' . Access::getGroupIcon($group) . '></i>';
		  $apps_links_responsive .= '			  <span>' . Access::getGroupTitle($group) . '</span>';
		  $apps_links_responsive .= '			  <b class="caret"></b>';
		  $apps_links_responsive .= '			  </a>';
		
		  $apps_links_responsive .= '			<ul class="dropdown-menu">';
		
		  foreach ( $links as $link ) {		  
			$apps_links_responsive .= '			<li><a href=' . OSCOM::getLink(null, $link['module']) . '>' . $link['title'] . '</a></li>';
		  }

		  $apps_links_responsive .= '			</ul>';
		  $apps_links_responsive .= '			  </li>';
		  }
		  $apps_links_responsive .= '			</ul>';
		  $apps_links_responsive .= '		  </div>';
		  $apps_links_responsive .= '		</div>';
		  $apps_links_responsive .= '</div>';
	  }
	  return $apps_links_responsive;
	}
  }
?>

and called it my header.html :

{iftrue logged_in}	
	  {value}apps_links_responsive{value}	
{iftrue}

for an efficient navigation :

[attachment=1466:AppsNav.PNG]

yes, i use Boostrap Twitter to build template (like, for example, joomla 3 : http://community.joomla.org/blogs/community/1671-joomla-30-alpha-2-notes.html )
-------------------

#2   sammysumer

sammysumer
  • Members
  • 37 posts
  • Real Name:Sammy Sumer
  • Gender:Male
  • Location:Australia

Posted 25 August 2012 - 11:32 AM

What ugly language PHP has become. Look at those backslashes. Oh my God. I want to throw up.

Please don't take this personally foxp2. I am criticizing the language itself not your code. :)

For instance the following line in the above code.

class value extends \osCommerce\OM\Core\Template\TagAbstract {

What the hell? :)

Edited by sammysumer, 25 August 2012 - 11:33 AM.


#3   foxp2

foxp2

    strong as a Twig

  • Members
  • 303 posts
  • Real Name:Laurent
  • Gender:Male
  • Location:France

Posted 09 December 2012 - 09:27 AM

solution in template class : https://github.com/haraldpdl/oscommerce/commit/b398c74dcecf1639bd8fea3e5c185b7261587bf6
:thumbsup:
-------------------

#4   sembrouille

sembrouille
  • Members
  • 67 posts
  • Real Name:brouillard
  • Gender:Male

Posted 14 December 2012 - 03:32 PM

View Postsammysumer, on 25 August 2012 - 11:32 AM, said:

What ugly language PHP has become. Look at those backslashes. Oh my God. I want to throw up.

Please don't take this personally foxp2. I am criticizing the language itself not your code. :)

For instance the following line in the above code.

class value extends \osCommerce\OM\Core\Template\TagAbstract {

What the hell? :)
+1

#5   foxp2

foxp2

    strong as a Twig

  • Members
  • 303 posts
  • Real Name:Laurent
  • Gender:Male
  • Location:France

Posted 14 December 2012 - 05:01 PM

<_<
please, clean trolls.
thanks.
-------------------