Joomla 3.x get params from style sheet to custom article layout - joomla3.0

I have started a new project using Joomla 3.6 but I am stuck with this problem.
I have added some feilds in template style layout.
I retrived in template index.php using
$logo = $this->params->get('logo');
$navposition = $this->params->get('navposition');
$headerImage = $this->params->get('headerImage');
but I didn't get that in newly created custom article alternative layout.
How do I call this in the custom layout?

You cannot use the same method to retrieve template params from anywhere. To do that you can use this method
$app = JFactory::getApplication();//Initiate the Application class
$template = $app->getTemplate(true);//get the current template
$params = $template->params;// get the template params
//Retrieve the variables using $params
$logo = $params->get('logo');
$navposition = $params->get('navposition');
$headerImage = $params->get('headerImage');

Related

CakePHP How to create pagination from API JSON data source

I have an API like example
I have used cakephp HTTP client to get data, below my attempted code
public index()
{
$http = new Client();
$response = $http->get('https://restcountries.eu/rest/v2/all');
// $json = $response->getJson(); //also tried usgin json
$countries = $this->paginate($response);
$this->set(compact('countries '));
}
I am trying to apply pagination with this country data then fetch it in view with pagination.
After tried above code , I have gotten below error
Argument 1 passed to Cake\Datasource\Paginator::extractData() must be an instance of Cake\Datasource\RepositoryInterface, instance of Cake\Http\Client\Response given, called in \myapp\vendor\cakephp\cakephp\src\Datasource\Paginator.php on line 176
How can I get my desire result ?
You have probably need to implement a class who extend RepositoryInterface.
class JsonSource implements Cake\Datasource\RepositoryInterface
{ ... }
public index() {
$http = new Client();
$response = $http->get('https://restcountries.eu/rest/v2/all');
$src = new JsonSource();
$src->fromResponse($response);
$countries = $this->paginate($src);
$this->set(compact('countries ')); }
Is a bit tedious, because you need to define Json like a datasource.
The default pagination only supports querying tables (repositories), or operating on pre-built query instances.
To extend on #Zeppi's answer. You basically have three somewhat straightforward options here:
Create custom query/repository implementations as hinted by #Zeppi.
This can indeed be quite a lot of work though, so you might want to look into alternatively implementing it with the help of plugins, for example muffin/webservice, which does most of the hard work of implementing the required interfaces.
Or create a custom paginator that actually accepts and works on array data.
Or use what is widely know as a "datatable", that is a JavaScript based table in the frontend that paginates the data, for example jQuery DataTables.

how can I load a joomla module as a link?

this is my problem...
I have some of images and links that I want to load different joomla modules when user click on them.
mean each hyperlink can load another module|position
thanks all
In case that you just want to call a module's content from a url the following answer will help you.
If you just want to show / hide a module in the same page you could use something similar to my previous answer: Joomla 3 Show different modules on same position depending on toggler
Joomla provides the functionality to call a specific file of the active template by adding the tmpl=FILENAME key/value to the url's query string.
All built-in templates have a component.php file if user wants to load the template with the component only. You could check the following link for more details: Adding print pop-up functionality to a component.
You could do something similar to only show the modules that you want to load.
You could copy the component.php to a new file (I have used custom.php) and added the following php code in the <body> ... </body> part.
<?php
$jinput = JFactory::getApplication()->input;
$selectedPosition = $jinput->getString("position", "");
$selectedModule = $jinput->getString("module", "");
$selectedModuleTitle = $jinput->getString("title");
if($selectedPosition !== "") {
$modules = JModuleHelper::getModules($selectedPosition);
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module);
}
} elseif ($selectedModule !== "") {
$module = JModuleHelper::getModule($selectedModule, $selectedModuleTitle);
echo JModuleHelper::renderModule($module);
}
?>
So with a similar way as loadposition / loadmodule works you could call the new template file using:
index.php?tmpl=custom&position=MODULE_POSITION
or
index.php?tmpl=custom&module=MODULE_TYPE
or
index.php?tmpl=custom&module=MODULE_TYPE&title=MODULE_TITLE
Optionally if you want to load the module with a specific style, you could pass it to the second paramter of the renderModule method like:
echo JModuleHelper::renderModule($module, array("style" => "xhtml"));
Hope this helps

CakePHP 3.x: Create a controller object

I am trying to create a list of controller objects
use App\Controller\AccessController;
foreach ($controllerlist as $controllerName){
require_once($path); // path for the controller
$clsobj = new $controllerName ();
$methods = get_class_methods($clsobj);
}
In this way I am getting a class not found error
EX:AccessController not found
but when I hard code the controller name and use it`s work
$clsobj = new AccessController (); // this way its work
Any Idea how to do ?

Add microdata to a Drupal site

Is there a way to add microdata to a Drupal 7 site by editing the field.tpl files? My site is built using panels and views so http://drupal.org/project/microdata isn't working. Is there another way to go about adding microdata by hard coding?
Thanks.
The best way to add microdata is by editing the field.tpl files and then checking - use file templates on views. For panels I used the module http://drupal.org/project/panels_extra_styles to add coding around the pane.
I managed to override the page template file and wrap my panel in a code.
The code I used was
template.php:
function ThemeName_preprocess_page(&$vars) {
// if this is a panel page, add template suggestions
if($panel_page = page_manager_get_current_page()) {
// add a generic suggestion for all panel pages
$variables['theme_hook_suggestions'][] = 'page__panel';
// add the panel page machine name to the template suggestions
$variables['theme_hook_suggestions'][] = 'page__' . $panel_page['name'];
$object = $panel_page['contexts']['argument_entity_id:node_1'];
$result_array = get_object_vars($object);
$value = $result_array['restrictions']['type']['0'];
if($panel_page['name'] == 'node_view' AND $value == 'product' ) {
$vars['theme_hook_suggestions'][] = 'page__node_view_product';
}
if($panel_page['name'] == 'node_view' AND $value == 'artist' ) {
$vars['theme_hook_suggestions'][] = 'page__node_view_artist';
}
and I created a files under ThemeName/templates
page--node_view_artist.tpl.php and
page--node_view_product.tpl.php
I hope this helps someone, it took me a long time to figure it out!

Puts Scripts and CSS in Initial request from internal requets

I have a main page(controller_welcome => C_W), and another controllers; these extends from Controller_DefaultTemplatre(C_DT). In C_DT i have a function called addScripts() and addCss() these adds to url of the javascripts files and Css respectly to the View template, and getScripts() this last function get the array of the Scrips added by the current controller.
In C_W I have an action that calls anothers controllers via Request::factory("KONTROLLER/AKTION"); and puts all in the current template request.
/* content of the C_W */
$params = array();
$controller1_request = Request::factory("controller1/index");
$controller1_response = $controller1_request->execute();
$params["extra"] .= $controller1_response->body();
$controller2_request = Request::factory("controller2/index");
$controller2_response = $controller2_request->execute();
$params["extra"] .= $funny_response->body();
$this->template->content = View::factory("welcome/index", $params);
My question is: How I can add Scripts to the C_W Template from the Request::factory("controller1/index");?
Static vars?
For example, rewrite your addScripts() and addCss() to work with a static properties, so you can call it from any instance of C_DT. Of course, those methods must be static.
Or create special static class (helper) for it.

Resources