简体   繁体   中英

How to include a php file for two different views in Joomla

I have the following good working code for my Joomla site which is loading a php file for a certain view:

$jinput = JFactory::getApplication()->input;
$view = $jinput->get('view');
if($view == 'pluginresponse'){
    include ("templates/default/datalayer.php");
    }

I would like to include this php file for a second view also. I have tried with the following code but unfortunately lack the knowledge in php so it is not working as expected:

$jinput = JFactory::getApplication()->input;
$view = $jinput->get('view');
$layout = $jinput->get('layout');
if(($view == 'pluginresponse') or ($view == 'cart' && $layout == 'order_done'){
    include ("templates/default/datalayer.php");
    }

Could I please get assistance or some info how to code this correctly.

Thank you

It looks like you may be missing a ")" modify

    $jinput = JFactory::getApplication()->input;
$view = $jinput->get('view');
$layout = $jinput->get('layout');
if(($view == 'pluginresponse') or ($view == 'cart' && $layout == 'order_done'){
    include ("templates/default/datalayer.php");
    }

to this

$jinput = JFactory::getApplication()->input;
$view = $jinput->get('view');
$layout = $jinput->get('layout');
if(  ($view == 'pluginresponse') or 
     ($view == 'cart' && $layout == 'order_done') ){
    include ("templates/default/datalayer.php");
    }

other than that I do not have a joomla install to test this with hope this helps

The best solution I got so far which is working perfectly for my needs it the following. As said it is maybe not the nicest solution but works.

$jinput = JFactory::getApplication()->input;
$view = $jinput->get('view');
if(($view == 'pluginresponse') or (strpos($_SERVER['REQUEST_URI'], "cart/order_done") !== false) ){
    include ("templates/default/datalayer.php");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM