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

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}

Related

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

Including Joomla! 3 module in custom position on custom component

I've seen alot of examples of how to include modules on a custom joomla! component using JModuleHelper::getModules, however, when trying to include modules in a custom position, the array come back empty. Here's my code in my component's template:
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('comwhcustomer');
foreach ($modules as $module){
echo JModuleHelper::renderModule($module);
}
?>
You'll notice the position I'm passing the getModules function is comwhcustomer. This code is returning a blank array. If I pass "footer", I do successfully get the module in the footer position.
I'm using an adapted protostar tempalte and I have added the comwhcustomer position to the xml definition file for the template. I've created the module in module manager and in the position filed, I've selected the "comwhcustomer" position that shows up in the dropdown. On the modules manager page, I see the module listed in the position selected (comwhcustomer). I've confirmed in the database table #__modules that the position is saved correctly.
However, the array is still coming back empty on the getModules call. What am I missing?
Joomla version 3.4.1
Local environment
Windows IIS
PHP 5.4.24
MySQL db
PS - As an alternative, I have sucessfully loaded the module with JModuleHelper::getModule() however, none of the attributes I define in the module manager come over, because they're not supposed to. I'd like to use the method mentioned above so I can control the module behavior from the manager rather than attributes in the code, because this position will be used in multiple views of this component.
This is my first time posting to SO. I do appreciate the support :-)
itoctopus, you were exactly right! The module itself was not assigned to any pages, that's the piece I was not taking into consideration! Thank you so much for your help! I set it to display on all pages and it worked!
Of course, it doesn't show up on all the other pages because they do not contain a position called "comwhcustomer" so it is exactly what I was looking for!

dojox mvc at() target

I've created a sandbox with a demonstration of binding UI components to both data and state: http://dojo-sandbox.net/public/51073/1
It's my plan to generate code from a page definition creating a page-level widget which is templated. This widget will have its own scope, where the model and state will reside, which I am trying to simulate in the sandbox by way of the Page object.
The sandbox is working because the Page object is in the global state, which appears to be the default context for object resolution in mvc binding.
However the plan is to have a view widget supporting each page with both the Model and State contained within the widget's scope. The generated template for the view would be bound to both the Model and the State. I can establish the source via the 'target' property, but when the same UI component must be bound to two different models, one for value and one for state, the single source doesn't support this.
The Model data will come to me from the back-end, and the State data is derived via the State.Execute method once the Model data is present.
I've taken a look at the 'rel:' parameter of at(), but don't see how to leverage this syntax within a specific context, ie my view widget's scope. It seems to be working fine for the default global scope.
Is there a standard way to direct the data-dojo-props value binding at one source, and the data-mvc-bindings for attributes at another? Or, more precisely, what is the at('rel:') syntax which will support specifying the context of the relation, and not rely on the 'target' of the widget or containing widget?
If there is no way to specify the 'target' at this level, I will generate more logic in the Execute method to specifically set the html attribute on the component during state compilation.
data-mvc-bindings is for allowing non-widgets use dojox/mvc/at. If a widget is declared for an element data-dojo-props is the one for use instead.
If target is specified via data-dojo-props or data-mvc-bindings, it’ll be set eventually to the widget.target. ”rel:” syntax looks for a widget having .target up in DOM tree.
It means that one “group” cannot have more than one "relative binding target”, in case it’s one of your questions. You can have a “scope object” that contains pointers to more than one models and use it as a “relative binding target”, that may serve a similar purpose:
<div data-dojo-type="dijit/_WidgetBase"
data-dojo-props="target: {model0: model0, model1: model1}">
<input type="text"
data-dojo-type="dijit/form/TextBox"
data-dojo-props="value: at('rel:model0', 'value'),
disabled: at('rel:model1', 'disabled')" />
</div>
A working example can be found at http://jsfiddle.net/asudoh/M3bRC/. Hope these help.
Best, - Akira

joomla + not render a module

I have developed a module for joomla 2.5 and it works just fine, the thing is I don't want it to be rendered when a certain view of a component is displayed but that view is not a menu link so I can't tell my module not to render when I don't want it to.
Two possibilities:
Assign that view to a menu item in a menu that is never shown. You can than hide the module as usual.
Since you have a custom module you could modify the module to check for the component and view and not render itself in certain cases.
One issue that you might have with "check for the component and view and not render itself in certain cases" is that if the module is in a module position that is supposed to "collapse" when there are no modules in it (e.g. a right or left column), it won't collapse because the module is still assigned (even though it's not rendering anything).
The issue is to do with where the decision is made to display the module. Is it a question of the module itself deciding when to render, or should the logic be somewhere else, that determines "on this page, should a particular module appear?". I suggest the latter.
A good solution for this is MetaMod Pro that allows you to build in conditions that determine whether other modules should appear on the page. You then put in a snippet of PHP to do the detection.
So the snippet might be:
if (! ($option == 'com_mycomponent' and $view == 'myview') ) return XXX;
// replace XXX with the module id of the module you want to disappear.
i.e. "if we're not on a page with mycomponent and myview, show module XXX".
Tip: the Pro version will allow the module to completely disappear if it's not included. The free version may leave some HTML behind.

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

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"){
...
}

Resources