I want to use specific Joomla template (with no navigation, no top and bottom) for users that connect to website through my mobile app with iframe in it. I assume that this users will start connection from specific address with tmpl param (or something similar) but is there a way to lock this template for these users?
Maybe there is some plugin to set template in session data and override default template choice?
There is a Joomla extension called Template Assigner - http://extensions.joomla.org/extension/template-assigner . It does exactly what you want.
Plugin allows me to set template only for specyfic user group, not to switch template accordingly to url but thanks to Your idea I created very simple plugin to do this, code below:
defined('_JEXEC') or die;
class plgSystemMobiler extends JPlugin
{
public function onAfterInitialise()
{
$app = JFactory::getApplication();
$jinput = $app->input;
if (isset($_REQUEST['mobile'])) $par=(int)$_REQUEST['mobile'];
if (isset($par)) $jinput->cookie->set('mobile', $par, time() + 100000, $app->get('cookie_path', '/'), $app->get('cookie_domain'), $app->isSSLConnection());
$cookie=$jinput->cookie->get('mobile');
if (intval($cookie)>0) JFactory::getApplication()->input->set('templateStyle', intval($cookie));
}
}
Related
I want to create a shortcode that will show the template parts mytheme/woocommerce/single-product/add-to-cart/variable.php on my Woocommerce product page where I want. My target is to set my page fully from WP Barkery on Long Description and not call this template part from templates files.
I made :
function shortcode_add_to_cart_variations(){
wc_get_template_part( 'single-product/add-to-cart/variable' );
}
add_shortcode('add-to-cart-variations', 'shortcode_add_to_cart_variations');
The template part is called but the variations it's not shown because $available_variations = NULL : https://github.com/woocommerce/woocommerce/blob/3.5.0/templates/single-product/add-to-cart/variable.php#L26
How can I make my shortcode and show variations where I want on my product page (for example in my Revolution Slider)?
I found myself the answer.
I only need to use the core woocommerce function woocommerce_variable_add_to_cart()
Detail here: http://hookr.io/functions/woocommerce_variable_add_to_cart/
Add this in my functions.php (child theme) :
function shortcode_add_to_cart_variations(){
woocommerce_variable_add_to_cart();
}
add_shortcode('add-to-cart-variations', 'shortcode_add_to_cart_variations');
I'm using play 1.1, I have a URL mapping routes file as,
* /show/{id}/ TestController.show
and TestController is specified as
public static void show(String id){}
When I use above route in my HTML template by #{TestController.show(id)}, I would expect to render as /show/23/ in the browser address bar, but like this instead its rendered as default mapping(/TestController/show?id=23) which has least priority in routes file. Can you please help me how do we render the URL as http://localhost:9000/show/23/?
The actions arguments has to be the same type as these passed in template so if you built href in template with #{TestController.show(id)} where id is porbably type of Long or int declare your action with the same argument.
public static void show(Long id){
... action's body ...
}
There is a cookbook for adding globals to the twig templating engine, but it doesn't get into doing the same thing for the php engine. How would I do this?
So I might have something like:
# config.yml
someSortOfReferenceToThePHPEngineInstance:
calls:
- [ addGlobals, ["foo", "bar"] ]
- [ addGlobals, ["myService", "#myService"] ]
And then access those like:
// templateName.contentType.php
<?
echo $foo; // echos "bar"
echo $myService->myMethod($foo); // echos the result of modifying "bar" with "myMethod" method of "myService" service
I could not find any documention on this for the PHP engine...
What does work however is:
Config:
//config.yml
parameters:
hello: "YO!"
PHP Template:
// index.html.php
<?php
print $view->container->parameters['hello'];
This does not fit as nicely as the twig convention... Maybe there is better way - I have not debugged any further...
Here are a couple of options:
If you create a base controller that all others inherit from, you can override symfony's render function and add keys to the parameters argument, like:
public function render($view, array $parameters = array(), Response $response = null){
if(!array_key_exists("bar", $parameters){
$parameters["foo"] = $this->get("foo");
}
if(!array_key_exists("bar", $parameters){
$parameters["bar"] = $this->get("bar");
}
return parent::render($view, $parameters, $response);
}
This is the only way I see to modify the "global" variables "globally", though they'll not be available in any views rendered by controllers you don't create (of course, those'll likely be done in Twig anyway and you can use the normal twig means of adding functionality).
The PHP rendering engine has what're called "helpers", which you can access via array keys of $view, like:
$view["foo"]->doSomething();
We created a class for easily making services into helpers:
use Symfony\Component\Templating\Helper\Helper as BaseHelper;
class Helper extends BaseHelper{
protected $name;
public $service;
public function __construct($name, $service){
$this->name = $name;
$this->service = $service;
}
public function __get($name){
if(isset($this->service->$name)){
return $this->service->$name;
}
}
public function __call($name, $arguments){
if(method_exists($this->service, $name)){
return call_user_func_array(array($this->service,$name), $arguments);
}
}
public function getName(){
return $this->name;
}
}
Then in our configuration under the services we'd add:
helper.foo:
class: %helper.class%
arguments:
name: "foo"
helper: "#foo"
tags:
- { name: templating.helper, alias: foo }
This would theoretically be available then to any view files, even those with controllers you don't have control of.
I had a very same problem. For some reason this feature is only available for Twig templating with TwigBundle. Both Twig and PHP templating engines provide possibility to define global variables, but only Twig engine has configuration for that. For me the only real way to achieve that is something you proposed in the question post - to define method calls (and this is the way Twig globals are registered).
Problem is, that with DI extensions you can't access service definition from outside your extension, so you can't add these calls from your DI extension. The way for me was to do that with DI compiler pass.
But I'm also developer of ChillDevViewHelpersBundle and since I was facing this problem in most of my projects I decided to implement it there for common use and you can use 0.1.8 release for this feature.
I don't understand the purpose of using templates in Kohana. I see almost no difference in the process of building a view with a template controller vs a regular controller, except that the template controller is tied to a given template and so is less flexible. What are the advantages?
Building view with regular controller:
Class Controller_Hello extends Controller
{
public function action_index()
{
$view = View::factory('page');
$view->page_title = 'My Hello App';
$view->content = 'hello, world!';
$view->sidebar = View::factory('parts/sidebar');
$this->response->body($view);
}
}
Building view with template controller:
Class Controller_Hello extends Controller_Template
{
public $template = 'page';
public function action_index()
{
$this->template->page_title = 'My Hello App';
$this->template->content = 'hello, world!';
$this->template->sidebar = View::factory('parts/sidebar');
}
}
Controller_Template is just an example of how you can implement your own templating-system.
It is not ready-to-use solution (at least for my projects usually). Check this one controller (it is also not ready-to-use solution but possibly it will help you understand point of extending different controllers for different purposes): http://pastie.org/2563595
I am sure there are other, maybe better solutions for templating systems. But why am I using templates in Kohana?
Think about multiple pages, all based upon one layout/design scheme. So I build a template controller using a certain view, defining layout/design, defining content, header and footer "areas". In the template controller I am loading the CSS files and script files, setting the title and meta values of the website, because every single site is using these CSS/script files with the same meta values and title.
So in every Controller extending the template controller I don't need to load the CSS/script files anew, set the meta values and title etc... But I could change all these values, maybe add a CSS file only for a single site.
Maybe all the mentioned sites have the same footer and/or header: I assign the header/footer view to the template within the template controller, so I don't need to do that in all the controller extending the template controller. Or all actions in one controller have the same header/footer, so I assignt he header and footer few in the before() function of the controller...
For me templates in kohana are a good utility for building small web applications.
Hello all im using this template system
http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html
but now i want to add a admin system to it, how would you do that?
make a map in controller/model and view calling "admin" but how can i then use the template system without conflicts :O?.
do you know a better way i will be glad if you will tell :)
Thanks a lot
Yes, you can create a view called admin and a controller called admin; there will be no conflicts.
Using a template library, you will want to do something like this:
In config/template.php
$template['admin']['template'] = 'admin/admin_template.php'; // in your views
// create a new template and its regions
$template['admin']['regions'] = array(
'header',
'content',
'footer',
);
then in your admin controller:
class Admin extends CI_Controller { //ci 2.0
function __construct()
{
parent::__construct();
$this->load->library('template');
$this->template->set_template('admin'); // set the admin template
}
// carry on as normal
}
i set up my routes to go through /admin and the actions that are for admins are in /views/admin/modelname
I also use tankAuth it's very good.