opencart - How to manually display a module inside a template file? - php

Let's say I want to display the specials module on the homepage in a position different than $content_top, $content_bottom, $column_left or $column_right. How do I do that? If you have some experience with this, could you give me some pointers?
The module will be display in home.tpl but I'm assuming I would need to edit the controller file home.php

To do this, you will need to make edits to two files
Firstly, you will need to edit the controller. In this example, I'm going to add the specials to the home page
So open the controller file catalog/controller/common/home.php. Somewhere before this line $this->response->setOutput($this->render()); add the following
$this->data['special_block'] = $module = $this->getChild('module/special', array(
'limit' => 5,
'image_width' => 80,
'image_height' => 80
));
The array is the settings for the module. Note that the layout, position, status and sort order aren't included, as they're irrelevant here. I've also used special_block as a unique key for the content, to avoid it conflicting with any other items that may need rendering
Then in your template file, you just need to use <?php echo $special_block; ?> wherever you want the module to go

Related

Preventing a specific CSS file from getting loaded in Yii

I am coding in Yii.
I have registered the main.css file in my main.php layout file like so :
Yii::app()->clientScript->registerCssFile($this->assetsBase.'/css/main.css');
Now this script is being registered in all the pages. However, say I don't want that script to be registered on a specific page.
I know that using :
Yii::app()->clientScript->reset();
would remove all the CSS files, however I want only few CSS files to be unregistered.
Is there a way to do it?
You can use the scriptMap property of CClientScript in your specific view, passing false for the particular script/css file's key that you don't want to be rendered. From the doc:
The array keys are script file names (without directory part) and the array values are the corresponding URLs. If an array value is false, the corresponding script file will not be rendered.
For example, in say views/site/pages/about.php:
Yii::app()->clientScript->scriptMap = array(
'main.css' => false
);
to disable the inclusion of main.css registered with registerCssFile.
The scriptMap can also be used for controlling the rendering of js script files.
I would suggest either:
Using a separate layout for that page like main_no-css.php
or
Adding a condition before registering the script (like if controller != xxx and action != yyy), but this would cause the condition to be checked on every other page.
I would definitely go for a separate layout.

How to make a template overwrite for mod_menu with alternative layouts for link outputs?

I understand and love template overwrites. I need to do some heavier changes to the menu output (basically making the output work better with Bootstrap) - but only for certain menus.
Currently in Joomla 3 there are the following in the mod_menu/tmpl folder:
default.php
default_component.php
default_heading.php
default_separator.php
default_url.php
If I want to change the classes I'd copy the default.php into my mytemplate/html/mod_menu and change it. Great, no problem.
If I want to change the link outputs to go along with that I can copy the default_component.php to mytemplate/html/mod_menu and change it. Great, no problem.
If I want to have the choice of having a different "Alternative Layout" I'd rename the mytemplate/html/mod_menu/default.php to newlayout.php, then select it in the admin module manager for that menu. Great, no problem.
Here's the problem: If I want to have the link output changed for certain menus but not all of them I figure I'd change default_component.php to newlayout_component.php like I did above which would correspond to the newlayout.php...but that doesn't work.
Questions:
1) How to have alternative layouts for each of the default_component.php, default_heading.php, default_separator.php, default_url.php template files (not just an overwrite)?
2) I would think default_url.php is the one that would affect the link outputs but it seems it's default_component.php that does. So what does each one of those do? I couldn't find any information on joomla.org about that.
Thanks!
The alternative layout feature only works for the main file (default.php), not for the sublayouts (default_component.php, ...). So you have to create your own newlayout.php which then can load newlayout_component.php, or use the default_component.php. In fact, the default_component.php will be used as fallback if no newlayout_component.php is found.
The code switches over the $item->type of the link. 'separator', 'url', 'component' and 'heading' are handled by the 'default_'.$item->type, everything else will use default_url. So a plain URL should indeed be generated by default_url.php, not default_component.php. If it behaves differently, it's likely a bug.

Drupal node 2-page content split

My employer requires certain pages on the website have a two page feature.
What this means is that some default content show up on the node_view page as normal but the second part should show up when a link is clicked.
This will be easy if I could do this across multiple nodes but the requirement is for all the data to be stored in one node but displayed across two pages.
I hacked together the following code:
function mymodule_node_view($node, $view_mode, $langcode){
$path = current_path();
$path_alias = drupal_lookup_path('alias',$path);
$links = array( 'test' => array('title'=>'my_link', 'query'=>'', 'href'=>"{$path_alias}/nextpage") );
$node->content['my_module'] = array(
'#theme' => 'links__node__mymodule',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
}
That creates a hyperlink called my_link across the top of my content area - which is great.
The problem starts when I click the hyperlink. Supposing I am on http://example.org/homepage and I click the hyperlink, I expect to be redirected to http://example.org/homepage/nextpage. Also, I still want to maintain the view and edit tabs of the actual node I was on. However, Drupal correctly gives me a "page not found" error.
What's interesting is if I used http://example.org/node/1 and visited http://example.org/node/1/nextpage, I don't get the issues I described above but the url is less descriptive.
To solve this problem, I am sure I have to extend hook_menu but I don't know how to account for any number of taxonomy terms leading up to the actual node title. So, I can't predict how many % I will need before the node title and then my /nextpage. However, I want /nextpage to still have the view and edit tabs of it's parent page.
This is all unexplored territory for me.
Update
I found the following function which does a great job of returning the entire node path complete with taxonomies:
$path = current_path();
$path_alias = drupal_lookup_path('alias',$path);
What I don't know is how to take advantage of this in hook_menu to dynamically create /nextpage for my nodes.
Please remember, I don't really want /nextpage to be entirely independent of the original and actual Drupal node. When on /nextpage I want to be able to have access to the view, edit etc tabs of the node.
So, /nextpage effectively is just an extension of a Drupal node page.
There is a quick way to do that. Using views module.
In the fields section choose the field you wanna view. And in the arguments add the nid.
Then add the link to the node view you already created.
The final result http://mysite/views-page/[nid]
Hope this helps... Muhammad.
I would check the node_menu() function to get some reference on how it's implemented.
Not sure on your taxonomy requirements so this might be insufficient but I'll go with what I understand.
But off the top of my head I'd go for something like:
function mymodule_menu() {
$items['node/%node/nextpage'] = array(
'title' => 'Next page',
'type' => MENU_LOCAL_TASK, // Makes it a tab on node/%node-pages
'page callback' => 'mymodule_node_page_view', // Your page display function
'page arguments' => array(1), // First will be a node object, second will be whatever value is passed in the url
// You should rip access callback and access arguments from node_menu()
);
return $items;
}
That should do something like what you are asking for.
It is also possible, easier and definitely recommended to do this with Panels/Pages (see also Chaos Tools) or arguably Views as they are quite capable of all this and generally a better way to work with Drupal's strengths than custom code.
Updated
To clarify I've simplified the menu hook and you should be able to use the below page view function. I still believe you would make a better solution using Panels and overriding node_view and such.
The MENU_LOCAL_TASK part in the menu hook should turn this into another tab along with View and Edit.
function mymodule_node_page_view($node) {
die("It works: ".$node->title);
}
Hope that's more helpful.

Overriding an article output in Drupal 7 using a template.php theme

I basically want to modify the output of my articles, by putting a between each article that is listed on my page.
I have overridden other functions in my themes template.php as follows
function mytheme_preprocess_html(&$variables) {
drupal_add_css('http://fonts.googleapis.com/css?family=Gudea', array('type' => 'external'));
}
I am looking for something similar for the articles?
Copy your theme's node.tpl.php to a file called node--article.tpl.php and add an <hr> at the bottom of the file.
Have you looked at the Views module? Take a look http://drupal.org/project/views and use it to list content for you. Views can create a Page display for this content. You can then apply styles to the Views-generated HTML that will allow you to put dividing borders between the nodes listed. Views provides 'first' and 'last' classes as well so that you will not apply a border to the last element.

ViewScript decorator unable to set

I am following the section about "Full Customization Using the ViewScript Decorator" from this page -> http://devzone.zend.com/article/3450
In the init method of my form class I have added this
$this->setDecorators(
array(
array(
'ViewScript',
array(
'script' => 'display.phtml'
)
)
)
);
Now in the place where my form appeared I have this:
An error occurred
Application error
What am I doing wrong here? I really need to customize the appearance of the form and I just want to change the form and not the appearance of the whole page.
I have tried this:
$this->setElementDecorators(array(array('ViewScript', array('viewScript'=>'display.phtml'))))
Which works but affects the display of the whole page (I am using zend layout). I just need the render of the form to be passed to the display.phtml page.
Note: Is there any place in particular I have to place the display.phtml? I placed it in the view\scripts folder.
I think it is as simple as this.
The ViewScript cannot be used in the init() method for your form for one simple reason. If you look at the example (and probably your display.phtml) there are echo statements like this one $this->form->firstname;. At this point in init() the form elements are not loaded yet!
The author therefore correctly shows this code
$form->setDecorators(array(
array('ViewScript', array('script' => 'demogForm.phtml'))
));
Note that he uses $form as the object. Either in controller or view script you load your form as an object and then add the ViewScript. So in one of your controllers you would do something like this
$form = new My_Form();
$scriptPath = '/path/to/script/display.pthml'
// or without a path if you have a script folder loaded
$form->setDecorators(array(
array('ViewScript', array('script' => $scriptPath))
));
This should do the trick.
Update Looking at the naming of your pthml I assume (and hope) this is a special template for your form and not your whole layout file. If you use your whole layout file then of course if will render the whole page!
When working with view scripts, I find it's best to make any such changes at the view level.
Ignore the "ViewScript" decorator details in your form and set them from the view, eg
<?php echo $this->form->setDecorators(array(
'PrepareElements',
array('ViewScript', array('viewScript' => '_forms/display.phtml'))
)) ?>
The location of the display.phtml file is relative to the module's view scripts folder. If this is just the default module (under the application folder), the script in my example will be located at application/views/scripts/_forms/display.phtml
If you want to remove HTML tags like <dt> or <dd> (labels and viewscript) you can use methods removeDecorator('HtmlTag') or removeDecorator('Label')

Categories