Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Front page conditional for X-Cart 5 Flexy templates?

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 04-22-2016, 03:38 PM
 
paulmighty paulmighty is offline
 

Member
  
Join Date: Apr 2014
Posts: 11
 

Default Front page conditional for X-Cart 5 Flexy templates?

Is there a way to determine if tpl code is running specifically on the store's front page? For example, some to the effect of:
Code:
{if:isFrontPage()} print this out only on the front page {end:}

All I'm trying to do is inject some text into the homepage / front page and not on every sub page and category page.

Thanks!
-Paul
__________________
X-Cart Version: 5.2
Reply With Quote
  #2  
Old 04-22-2016, 06:09 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Front page conditional for X-Cart 5 Flexy templates?

http://kb.x-cart.com/display/XDD/How+to+find+out+what+page+is+currently+running
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 04-25-2016, 06:08 AM
  seyfin's Avatar 
seyfin seyfin is offline
 

X-Cart team
  
Join Date: May 2004
Posts: 1,223
 

Default Re: Front page conditional for X-Cart 5 Flexy templates?

Code:
{if:getTarget()=#main#} THIS IS A HOME PAGE {else:} THIS IS NOT HOME PAGE {end:}
__________________
Sincerely yours,
Sergey Fomin
X-Cart team
Chief support group engineer

===

Check this out. Totally revamped X-Cart hosting
http://www.x-cart.com/hosting.html

Follow us:
https://twitter.com/x_cart / https://www.facebook.com/xcart / https://www.instagram.com/xcart
Reply With Quote

The following user thanks seyfin for this useful post:
benlind (03-09-2017)
  #4  
Old 04-25-2016, 08:43 AM
 
paulmighty paulmighty is offline
 

Member
  
Join Date: Apr 2014
Posts: 11
 

Thumbs up Re: Front page conditional for X-Cart 5 Flexy templates?

Quote:
Originally Posted by seyfin
Code:
{if:getTarget()=#main#} THIS IS A HOME PAGE {else:} THIS IS NOT HOME PAGE {end:}

Exactly what I was looking for. Thank you kindly!

Do you have any suggestions on how to learn what functions are available for X-Cart 5? I have had very mixed success navigating the documentation on my own.
__________________
X-Cart Version: 5.2
Reply With Quote
  #5  
Old 04-25-2016, 08:58 AM
  seyfin's Avatar 
seyfin seyfin is offline
 

X-Cart team
  
Join Date: May 2004
Posts: 1,223
 

Default Re: Front page conditional for X-Cart 5 Flexy templates?

I was glad to help you.

Just for your further reference:

1) Product page
{if:getTarget()=#product#}

2) Search page
{if:getTarget()=#search#}

3) Checkout page
{if:getTarget()=#checkout#}

4) Order confirmation ("Thank you for your order") page
{if:getTarget()=#checkoutSuccess#}
__________________
Sincerely yours,
Sergey Fomin
X-Cart team
Chief support group engineer

===

Check this out. Totally revamped X-Cart hosting
http://www.x-cart.com/hosting.html

Follow us:
https://twitter.com/x_cart / https://www.facebook.com/xcart / https://www.instagram.com/xcart
Reply With Quote
  #6  
Old 04-25-2016, 08:56 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Front page conditional for X-Cart 5 Flexy templates?

Quote:
Originally Posted by paulmighty
Do you have any suggestions on how to learn what functions are available for X-Cart 5?

Every page has a controller class that handles its logic. You can find these classes in the \XLite\Controller\Customer namespace.

The name of the controller class is determined from the "target" parameter. The default "target" is "main", that links to the \XLite\Controller\Customer\Main controller class. It is the home page.

When you submit some data and want the controller to perform some action, you also submit the "action" parameter. X-Cart 5 checks the controller class, finds a matching "doAction{your_action}()" method and executes it.

If there is no "action" parameter, X-Cart 5 executes the "doNoAction()" method. There is another method that is executed every page load: "handleRequest()".

When the controller class has completed its work, X-Cart 5 starts rendering the page. The logic is as follows:
- it renders the base template that adds multiple "view lists"
- it looks for templates and widget classes having "@ListChild" directive and renders these into the "view lists" that are specified in the directive
- these templates may add their own "view lists", so this is some kind of a loop
- if a widget class wants to limit the "targets" where it should be rendered, it can use the static "\XLite\View\AView::getAllowedTargets()" method

Inside template files you can access methods provided by the associated widget class and the controller class for the current "target". When you run something like "getTarget()" inside your template, X-Cart 5 looks for that method in the current widget class, and, if it is not there, it looks for the method in the controller class. "getTarget()" method is the controller's method that comes from the "\XLite\Controller\AController" class.

When you render a base template, the associated widget class is \XLite\View\Controller. But as soon as you start rendering a widget, that widget's class becomes the "current" widget for all templates it renders (unless some other nested template renders another widget).

I hope this clears the logic a bit.

You may also check the existing source code and our knowledge base for examples - this may really help.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #7  
Old 04-27-2016, 12:55 PM
 
paulmighty paulmighty is offline
 

Member
  
Join Date: Apr 2014
Posts: 11
 

Default Re: Front page conditional for X-Cart 5 Flexy templates?

Thanks Qualiteam, your direction is very helpful. Much appreciated.
__________________
X-Cart Version: 5.2
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:23 AM.

   

 
X-Cart forums © 2001-2020