play 2.0 how can i overwrite my views out of a (securesocial) module? - view

I'm using the securesocial plugin and use it as a module.
So my Structure is like:
project
|
|--app
|---|
|---|--views/main.scala.html
|--conf
|--logs
|--module
|---|--securesocial
|---|------|
|---|------|--app
|---|------|---|
|---|------|---|--views/main.scala.html
|---|------|---|--views/login.scala.html
My simple Question is, HOW can I overwrite the main.scala.html from my module/securesocial/app/views with my "main.scala.html"-view in my "app/views"-folder?!
I mean with "overwrite", that I can include the login view into the "#content"-variable of my main.scala.html, that normally would work like:
#main("My title test"){
<p class="note">
Try <em>guillaume##sample.com</em> with <em>test123</em> as password.
</p>
}
But with "#main" I can not access (and therefore overwrite) my "app/views/main.scala.html" out of the module folder.

SecureSocial renders views using a plugin that you can customize The default implementation is DefaultTemplatesPlugin that you can replace with your own to change the generated html.
To create custom pages and emails:
Create a new directory under views to place the custom templates for SecureSocial.
Create a new plugin that implements the TemplatesPlugin trait and renders those templates.
Edit the play.plugins file and replace DefaultPluginsTemplate with your own class.
You can see what methods you need to implement by looking at the TemplatesPlugin trait or in the documentation page: http://securesocial.ws/guide/views-customization.html.

Try giving it the exact package name for the view:
#views.html.main("My title test"){
...
}

Related

How to use a module's property in an other module in Jahia 7?

As mentioned in the title, I have different modules that I use in a template and I want to use a module's property in an other module. Is there a way to do it in Jahia 7 ?
Yes, it's possible. The correct way to do that is to include a fragment view of the other module into the main/calling module.
Example:
Delegating rendering (Employee definition/module needs to render a field/views from Company definition/module)
mynt_employee/html/employee.jsp
<h2>${currentNode.properties['jcr:title'].string}</h2>
<h3>Company</h3>
<template:module node="${currentNode.properties.company.node}" view="hidden.name" />
This code delegates the rendering of a company content to the company component
mynt_company/html/company.hidden.name.jsp - You just need to display the field that you want (here the title of Company):
${currentNode.properties['jcr:title'].string}

How to create a New Page on Prestashop 1.7 Child Theme

I want to create a new page on my prestashop. I dont want to use the CMS to create the page, I need essentially a totally new page.
I have tried duplicating current .tpl's and renaming them - but I can never navigate to them - what is the url to access the new template?
E.g. say my site is www.xyz.com the "my account" template, sits under template/customer/my-account.tpl this my account page is normally accessed at xyz.com/my-account
I want a new but similar page - so I duplicate this template, rename it to my-account-new and change something in it, why can you not access the new template by change the URL to end with my-account-new - I just get a 404.
What am I missing?
Thanks
:)
you can add a new front controller in a custom module :
ModuleName/controllers/front/ControllerName.php
Then your new controller is a class that should be defined like :
Module::getInstanceByName('<ModuleName>');
class <ModuleName><ControllerName>ModuleFrontController extends ModuleFrontController
Then you add the method
public function initContent(){
parent::initContent();
$this->setTemplate('<templateFolder>/<templateName>');
}
You can now navigate to the template by going to index.php?fc=module&module=ModuleName&controller=ControllerName
So in this example replace every ModuleName with the name of your custom module and ControllerName with the name of your controller (for example MyCustomModule and MyCustomController).
The template will be in the your theme folder for example you can add customAddress in themes/ThemeName/templates/customer/customAddress.tpl
in which case the call to setTemplate would become :
$this->setTemplate('customer/customAddress');
I hope this helps.

Joomla Terminology: view, layout, task and component development

I'm a developer and I am very confident with MVC pattern and have already developed a lot of webapp from scratch using php framework like symfony or yii.
I'm a little bit confused about joomla mvc and terminology and after googling a lot, read joomla book extensions guide, read on joomla website my doubt are still there.
What is confusing for me is the component mvc structure and how I have to set up "my way of think" about joomla mvc, for doing the things in the joomla way.
In particular I am used to reasoning in terms of controller/action (like in symfony and yii framework)
So the final list of all my webapp url will be
controller1/action1
controller1/action2
controller1/action3
controller2/action1
controller2/action2
Each controller's action will decide what view to render and what layout to use for showing the view.
In particular in these frameworks, the definition of a layout is exactly the mean of a layout. And the view is the "core part" of the page.
So I can have a view with a list of users and I can put this view inside a mobile layout or a desktop layout, or to build a view for mobile and put it only in the mobile layout and so on.
The final result about directory structure in my webapp is something similar to the following:
controllers/
controller1
controller2
controller3
models/
modelForTableA
modelForTableB
views/
controller1/
viewForAction1
viewForAction2
layouts/
mobileLayout.php
desktopLayout.php
and for me is very clear to understand.
So finally my questions are:
how would be the directory structure in joomla?
what are in joomla the definition of view, layout and task?
I need to clarify that I do not need an explaination about MVC works in general, but if I would achieve the same result as before, how I have to organize my code and my work?
Suppose that I want to build a component with the following "url"
userController/addUser
userController/editUser
userController/listUsers
userController/viewUserDetail
anotherController/addOperation
anotherController/editOperation
anotherController/myNonCrudOperation
Thank you very much
Routing in Joomla is slightly different. The SEF URLs are built from menu items, which in turn point to a View/Layout combination.
This turns things around: a controller is not bound to a specific View/Layout.
Let's make an example of the flow with the addUser functionality you mentioned as an example; I'll be referring to these files (but you'll have plenty more):
/controllers/user.php
/models/user.php
/views/useradd/view.html.php
/views/useradd/tmpl/default.php
/views/useradd/tmpl/default.xml
/controller.php
/router.php
As you can see the layouts are inside each view's tmpl folder.
router.php
Let's start from this last file: router.php defines our custom SEF rules so, after Joomla passes the call to our component (usually with the params
?option=com_componentname) we can takeover and interpret the URL as we wish. It is a bit hard to get started with but does provide the most flexibility and power. We don't really need to implement it at all for this simple example: so back to our registration now.
First step: show the "new user" form.
You would typically bind this to a menu item, pointing to the /views/useradd/tmpl/default.php; the /views/useradd/tmpl/default.xml contains the definition of the layout so it's available in the menu manager. Very often there is only one layout per view.
Control is passed to the view /views/useradd/view.html.php , and the view will then load an instance of its own model (automatically chosen based on the view name, you can load other models of course) to gather any initialization data.
The view then renders the layout, and presents it to the user.
The layout's responsibility includes generating a form with an appropriate action (endpoint) and security tokens if appropriate:
<form action="index.php?option=com_mycomponent">
<input type="hidden" task="user.save">
<?php echo JHtml::_('form.token');?>
as you see it doesn't really matter if you want to use <input or params on the url, and you can most often mix them.
Form interaction
For autocompletion the form may need to invoke some backend controller methods, i.e. the method emailAvailable() in the /controllers/user.php
It does not make sense to have such functionality indexed, so we'll invoke the method directly with a non-SEF url:
index.php?option=com_ourcomponent&task=user.emailAvailable
followed by any other parameter. This will work in both get and post.
The controller /controllers/user.php's emailAvailable() method will return a json structure and then invoke exit() as we don't want the CMS to kick in at all. An alternative solution is to add the param &format=json in the call.
{"email":"johndoe#example.com", "available":true}
Saving the data
When the user submits the form, processing is first handled by the controller since a task is specified. (see above task=user.save). Joomla will invoke the method save() in the controller /controllers/user.php.
This time, however, our controller is responsible for returning information to the user. After processing the data, it may choose to re-render the registration form showing an error, or a thank you page. In either case the controller simply sets the redirect, letting Joomla handle the rendering when appropriate.
$this->setRedirect(JRoute::_('index.php?option=com_yourcomponent&view=useradd', false));
More control
Each time a controller task is not specified, the display() method of the main controller is invoked. You can add custom logic there.
Joomla fires several events during a view rendering; these can be intercepted by a system plugin or - if you add in the calls - other kinds of plugins as well. You may even create your own types of plugins. Do not try to instantiate a view manually from a controller, as this may inhibit plugin firing.
Small insight,
1) Directory Structure
controllers/
controller1
controller2
controller3
models/
modelForTableA
modelForTableB
views/
layout1
2) View and layout and task
check this answer
3) More routing techniques with SEF.
Hope it helps.
solved with this. I cannot delete this question because there already exists other answer.
Could any moderator close or delete this? Thank you
https://joomla.stackexchange.com/questions/18774/joomla-terminology-view-layout-task-and-component-development/18799#18799

Load Magento module template

For a Magento module I need to load template file and let it replace the complete page. It is a XML file (but could also be any content whatsoever).
Generally speaking when
MYNS_MYMODULE_controllernameController is triggered and calls fooAction() I need to be able to display a clean site with the content from my template file.
Please let me know where to place the template file and how to tell Magento to load this file as a root template without anything else around.
Edit, to clarify it more:
For http://domain.tld/modulename/controller/action/
Where do I have to place template files and how should I reference them?
You could do it like this
$this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/1column.phtml');
$this->renderLayout();
or to set a custom response
//$file = myfile or html
$this->getResponse()->setBody($file);
$this->renderLayout();
Ideally your template should sit in /app/design/frontend/mypackage/mytheme/template/mytemplate.phtml
You should read Magento doc and Alan Storm Blog. Alan also wrote a book about Magento Layout: No Frills Magento Layout.
Your url: http://domain.tld/modulename/controller/action/
The modulename_controller_action Handle is created by combining the route name (modulename), Action Controller name (controller), and Action Controller Action Method (action) into a single string. This means each possible method on an Action Controller has a Handle associated with it.
In your layout xml handles this request:
<modulename_controller_action>
......
</modulename_controller_action>
Hope my suggestion is useful for you.

Joomla: How to change template on a specific article

Is there a way to change the template on a specific article only?
Note that it should work without linking the article to any menu.
If you want the template override not to depend on the menu position than the standard joomla way of assigning a different template to a menu will not work. You will need to get your hands dirty and write some custom code. You will need to use the article_id as a trigger for template switch.
I did something like that at work but don't remember now how exactly this is achieved. I will post my code here as soon as I locate it.
EDIT: Found the code :)
You need to edit the file /includes/application.php, specifically the getTemplate() method. At the end of this method, just before:
// Fallback template
if (!file_exists(JPATH_THEMES.DS.$template.DS.'index.php')) {
$template = 'rhuk_milkyway';
}
you can add your condition for applying a custom template, like so:
//CUSTOM TEMPLATE FOR THE ARTICLE 13
if (JRequest::getVar('id')=='13' && JRequest::getVar('option')=='com_content') {
$template = $custom_template_name;
}
This will apply the custom template which name is inside the $custom_template_name to article with id=13. You can also use it to apply a different template to components, like I did with simplecaddy:
//TEMPLATE FOR SIMPLECADDY
if (JRequest::getVar('option')=='com_caddy'){
$template = 'shop';
}
You should really try to stay away from hard coding anything in to the template if it can be avoided. Not sure why you would specify that the article not be linked from a menu. The easiest way to accomplish this without having to write and code is to create a new menu, then add a menu item that links to the article you want to specify the template for. You don't have to put the menu in a module anywhere so it will never show up on the site, but it will show up in the menu assignment in the template manager.
You can do this with single articles, categories, sections, or even components. As long as you have a menu link to associate the template to. I always create an Admin only menu to put links that are needed to run the site, but do not need to be accessed by users.
As Brent said, avoid the temptation to modify core Joomla code! Doing this will likely stop you from doing Joomla upgrades 'cos you know it's going to break the core changes that you made.
Apart from the "hidden menu item" technique (which is useful but can break SEF URLs in some situations), a useful tool is Chameleon. This allows you to select specific articles/categories/sections (plus things like browser type, user group, component, whatever) and use these to trigger a certain template.
Though this is an old post, I thought I'd share my thoughts: You can easily change template on a single article, by implementing the onAfterInitialize() - function in a system plugin. No need to modify the Joomla core.
This works for Joomla 1.5, but should also work in 2.5:
function onAfterInitialise(){
if(true){ // f.ex. test for article ID or whatever
JRequest::setVar('template', 'beez'); // change template
}
}
In joomla 3.x versions, url-parameters are handled differently. The following was tested in joomla 3.4.8:
public function onAfterInitialise()
{
$app=JFactory::getApplication();
if(true){ // f.ex. test for article ID or whatever
$app->input->set('template', 'beez3');
}
}
More on writing plugins for Joomla here

Resources