What does mean 'default_' part of a template view in a component? - php

I have noticed that a name of a template in joomla's component view begins with "default_" part. What the reason for it, how it can be changed?

you can simply create different template overrides as you like. F.ex. in com_content article view, make a copy of default.php and call it simple.php. You can display the new article template by calling index.php?option=com_content&view=article&tmpl=simple&id=an-id.
The _ - notation is to be able to divide the template into logical parts. F.ex. for the category blog-layout you have blog.php as the entry-point. The blog-layout is looping throug the content items in the category, and calling blog_item.php for each article item. So code relating directly to each article is handled here. If you override files in the template, you can choose to only override one of the files( like blog_item.php ), and let the other file get handled by by the component as usual.
regards Jonas

Related

How to override a block template created using views

On Drupal 8 I'm trying to override the template of a block created using views. So far I've a file name as block--views-block--xxx.html.twig which gives me access to the view fields.
I've to do something like content.view_build['#rows'].0['#rows'] to get the rows which is pretty awful but I couldn't find any other way. Also I've to set "Show content" on the views settings.
I can not get the pager to work at all. Reading the documentation from Drupal I can not find any clues.
Turn on twig debugger (he's showing, in inspector tools, all templates what used now).
In inspector tools you see something like this:
- html--internalviewpath.html.twig
- html--node--id.html.twig
- html.html.twig
Then just create template with this name add you custom architecture. For example: html--node--id.html.twig. Check you can hear to, you see this:
- html--internalviewpath.html.twig
+ html--node--id.html.twig (now twig use this template)
- html.html.twig
I think you should rather override the view template rather than the view-block template.
View templates Naming conventions can be found here and the variables you can work with are listed here. you can now put the pager, header, rows and other view elements in different sections in template.
If you need to override the contents of the view rows then you will need to take action according to how you are displaying the content in the view.
If you use a teaser view of content you can override the content teaser template like "node--content_type--teaser.html.twig", or if you use fields in view then you will have to override the fields templates of each field.

more than one text separator style per template in joomla 3.0

Let me first explain what I am trying to do.
In joomla 3.0 I have created a Menu_Item_Text_Separator override for my template http://docs.joomla.org/Help30:Menus_Menu_Item_Text_Separator. It seems as though joomla will only recognize one default Text separator per template which is ok if you just want the one. but I ideally would like to have the choice of selecting the custom one in my template folder as well as the default one that joomla recognizes. To inform you this is what I have done to make it happen.
in my template I have a folder named html which had a folder called mod_menu inside it.
In the mod_menu folder I have the .php files called:
default_separator.php
custom_separator.php
I then go into menu manager and edit the menu item for which I want to display a text separator for.
I then go to 'template style' http://docs.joomla.org/Help30:Menus_Menu_Item_Text_Separator and look for my custom style. but I only can choose the default one.
So i wonder if this is way that joomla works that you can only have one default per template. but is it possible to have more than one?
any advice most welcome.
regards
w9914420
Sorry this got too long for a comment.
Okay let's start from the beginning. Templates have a set of parameters defined in the templateDetails.xml file. A template style is simple a record containing the information about a template and the array of parameter options you have selected. You can make as many template styles as you want for a given template Each one has its own name. In the menu you can select any of the styles and assign it to a menu item. ....
What you are talking about has nothing to do with template styles. You are talking about using a layout override for mod_menu. Because you are using a file with the same name as a core layout file you should get a 1:1 replacement.
From what I understand of what you want to do, you should instead make a new named replacemen both for default_separator and for default.php. THat's because the alternative layout field is going to look for a replacement for default.php say yourname.php and then in that replacement when you load a template called separator it is automatically going to look for yourname_separator rather than default_separator because it assumes you are appending the _separator to the base name. If you do this it has some advantages such as you will be able to make a more complex layout and it will allow you to load different sub layouts conditionally for example.
I think your are confusing template styles with the style for menu module. Unless you have a parameter in your template that specifies the choice of a mod_menu layout a template style is not going to help you.Go to he module manager and pick the module you want to apply the style to. Use the field to select the layout you want. Or if it is a css style use the style option. It could also be that what you really want is to apply module chrome. THat do can be done by editing the module. If you want to have the same menu with different layouts or styles you'll probably want to make additional modules for that menu.
I had a rethink of what i was trying to do. What I was trying todo could not be achieved through the method I hoped - creating a template for that one text separator would not be practical although I have now discovered how to feed template parameter values into layout overrides.
Thank you Elin for your time
regards w9914420

How to add a new view (and also a new Menu Item Type) to existing joomla 2.5 components?

Maybe I want to add a new view, and also a new Menu Item Type to content component.
What are the steps please?
UPDATE
Question (by #ValentinDespa) :
You want to extend com_content functionality or you want to override a
view or to build a new component that does something?
As I said, I want to extend com_content and add a new view to it. There are some views like Single Article, Category Blog, and Category List right now.
I want to add another menu items called Article Titles, so titles only will be displayed but with some parameters (like columns count).
It is a need that is not supplied by current features.
NOTE
Guys, it doesn't matter what my new view should be like, please tell me How to create a new view.
Yes You can create a new view.
Its simple just copy any of the view (category,blog) from your com_content.
The file structure should be like inside the folder.
Step 1
view.html.php
tmpl
your layout names(default.php)
xml file.
Also remember to change the class name of the view.html.php
Step 2
Add a controller file (just make a copy of existing one category or blog)
Controller name must be your new view folder name.
Also remember to change the class name of the controller
step 3
add a model file for your new view (same make copy of any existing)
remember to change the class name and file name should be view folder name.
Then you can access this view by giving correct url.
eg: www.example.com/index.php?option=com_content&view=yourviewname&layout=yourlayoutnames.
Here I mentioned view folder name must be controller and model file name we can achieve with other name also but it will create problem for you when you are not good in joomla.
Note:
For adding a view you don't need to install a component its not a good idea at all.
Also You can add multiple layouts in a view
inside your tmpl folder just create new files.Also don't miss the controller and model to put in com_contents/controller and com_contents/model folder
for More help take a look at this

Need a light understanding MVC pattern

You have the URL:
http:///www.site.com/controller/method/values/1/2/3
Do I have to always have the controller being called or can I have the view being called and instantiate the controller inside the view or in a bootstrap file referring to this view?
What I don't get it is if I need more than 1 controller on the view, how to archive that?
For example:
On my index page I want run a simple CMS, where the admin can change the text blocks and images of the site. That would be on the content management controller.
On my index page I also got the latest added products vitrine, what would be controlled by the controller products.
If I define www.site.com/contentmanagement or www.site.com to run the contentmanagement controller, how the product controller would be called?
Also, another example. On my menu I got a link to a page called aboutus, that would be a simple page and the only feature needed would be the content management controller to manage the texts blocks.
If I follow the pattern Im reading all over the place I will end with a link like:
http://www.site.com/contentmanagement/method/aboutus
?
Kinda lost here cause surely this URL will look weird. Would be much easier to have the URL calling the view http://www.site.com/aboutus and a boot file where I can tell the controller that should be loaded when the surfer is there ...
bootstrap would look like:
switch($view)
case: index
controller load contentmanagement
controller load product
case: aboutus
controller load contentmanagement
I appreciate any help or a light here, thanks.
by the way, Im coding in PHP.
Hm, if you want to have text blocks and images of the site (one controller), and products vitrine (second controller), then call the methods you need in one controller..
I would do it this way: when you request index page with all the elements you mentioned above, actually one controller is called, and it decides which view to show.. so in that controller, you call the all methods that you need, get the data, and pass it to the view.. if the methods are called from other controllers, just call that methods and get the data.. i often make some static methods in controllers, which I can call anywhere, so I don't have to instantiate whole object..
E.g. you call www.site.com/contentmanagement, controller is called, which will display index view, and in that controller, you call all methods you need, prepare the data, and pass that data to the final view which will be displayed..
Do I have to always have the controller being called or can I have (..blah blah..)?
It kinda depends on what you understand by "call".
Controller needs an ability to change state of both View and Model(s).
And each View need ability to request data (in Model2 MVC) from Model(s).
Thought Controller should not cause the rendering of View (which is common in all the RoR sycophants) much like View has not business in executing actions on the Controller.
What I don't get it is if I need more than 1 controller on the view, how to archive that?
Views and Controllers should have 1:1 relationship. If your view need more then one controller, you might want to look into HMVC architecture.
For example: On my index page I want run a simple CMS, (.. more blah .. ) how the product controller would be called?
CMS should be a separate application ( or at least module ) with multiple controllers.
If I follow the pattern Im reading all over the place I will end with a link like: http://www.site.com/contentmanagement/method/aboutus ?
Why not just http://site.com/cms/content/2/edit (where 2 is the ID for "about us" page). There is no law which states that URL structure for site administration must mirror the publicly available page .. hell .. it can actually cause increased vulnerability.
I am going to try to walk
What I don't get it is if I need more than 1 controller on the view,
how to archive that?
For example: On my index page I want run a simple CMS, where the admin
can change the text blocks and images of the site. That would be on
the content management controller. On my index page I also got the
latest added products vitrine, what would be controlled by the
controller products. If I define www.site.com/contentmanagement or
www.site.com to run the contentmanagement controller, how the product
controller would be called?
Having the URL to contains the controller's name is definitely nice, but it is not the requirement for MVC. So you don't have to necessary map your controller to the URL itself. A classic MVC does not tie itself to a particular naming convention, so you could call your product controller via different URL which then process the product and show the view for the product.The important for MVC is to have one controller that deals with sets of model and resulting in one view as the presentation layer. In your particular example, your entry point seems to be a single controller that interacts with both ContentManagement and Product Class/Module and the resulting interaction produce a single view.
bootstrap would look like:
switch($view)
case: index
controller load contentmanagement
controller load product
case: aboutus
controller load contentmanagement
Thus your original interaction above is not completely off, except that you are not really calling two controllers, but rather doing the following upon hitting index:
Load a controller, let's call this one IndexController
Load ContentManagement module to get the related content, you might want to put the info as part of your Model for the Index page
Load Product module to get related products, again put this into your Model
Pass the Model containing the info for rendering the page into the View
In your View, you render the Model that contains both Content from ContentManagement module and Product list from the Product module thereby producing a single view
If I follow the pattern Im reading all over the place I will end with
a link like: http://www.site.com/contentmanagement/method/aboutus ?
This is again not a requirement, you should follow what makes sense and easier for the users. Also, if you are required to follow the conventions, you could always make your URL pretty by using URL mapping.
What you are looking for is called HMVC and there are a couple of frameworks for that out there, like Kohana.
Also see this question:
What is the HMVC pattern?

Good logic of View helper for CodeIgniter

Could someone tell what is good logic for creating custom helper for Views?
What I would like to accomplish is...
load header
load main navigation (static for all pages)
load some widgets etc. (static for all pages)
load content/main pages (dynamic)
and in the end, load footer of course
Could someone point me to the solution?
Thanks a lot, in advance!
This question gives some explanation to the method dqhendricks describes. It includes code examples showing how to use $this->load->view() to return the view to a variable instead of outputting it to the browser, how to include sub-views, and using a specific view as your main template. It's the best way I've found of handling view logic. Getting the hang of CodeIgniter - Templating / loading views
Some people will create a master template, then pass the sub content's view name in the data object. The master template will call the header view, footer view, etc, and use the data array to dynamically display the correct sub content view.
For a Template library that is more actively developed than Collin's (linked by predrag.music) try out mine:
https://github.com/philsturgeon/codeigniter-template
His is good but this supports modules, themes, mobile version variations of themes and plenty more.
you could use inheritance chaining (with a custom controller class or with an included extra class that extends controller that you extend from your controllers instead of the controller class) to make a common controller hub for all pages that has a method for the top stuff, and a method for the bottom stuff.
If you need something for the reference this one is good:
http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

Categories