Joomla component building Views contradiction - joomla

Link1: http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Adding_backend_actions#Adding_an_editing_view
Link2 :http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#Setting_the_view
In the above two links Link1 view is calling edit.php to display the view
and in LinK2 is using default.php to display the view.
Now my question is that which thing is forcing these two views to use different files i.e. default.php and edit.php, though structure of these two views is almost same

In Joomla component you can set different layouts for your component.
here two different layout is used default and edit so you can set layout by using
index.php?option=com_helloworld&layout=edit
Also you can set the layouts from your view.html.php
$this->setLayout("layout name");
hope its helps..

Related

Joomla: Override Category Blog output multiple times?

Yes. I want to override output of Category Blog component to 2 different display styles.
For first style, i copied and edited blog_item.php & blog.php in [mytemplate]/html folder. Then i choose template style from dropdown in backend of my category blog. That's worked. The display of category blog change as i expected.
But if i want to create another style and use in another category blog. How could i do ? And how to i named my files ( I tried blog_1.php, blog_item_1.php ) but only see my first style display in backend.
I'm using joomla 2.5.
Please help me. Thank you very much !
=================================================================================
[UPDATED]
I solved this issue. Here my solution:
Clone my template to [my_template_2]
Go to [my_template_2]/html/com_content/category then edit blog.php, blog_item.php as my needs.
Go to backend, at my category blog menuitem, i assigned [my_template_2] as its template style.
Then it worked. Both my category blog have its own style.
This maybe not very good solution because i have to use multiple templates, but at this time it's quite enough for me.
Thank you, stackoverflowers.
=================================================================================
[UPDATED 2]
Now, with multiple template styles, I could create unlimited styles for my category blog component within just only one template. That's very much better.
As you may know, joomla doesn't let developers make different styles for its components.
I think you have to list all menus which are made by "category blog component" in template managing page and let users set each menu style at there.**
and at blog.php, check template setting and then load customized style...
** you have to develop a custom field element which list all "category blog component" menus.
* you can use this code to accessing template parameters in component's template :
$app =& JFactory::getApplication();
$template = $app->getTemplate(true);
$paramsTemplate = $template->params;
$style = $paramsTemplate->get('style');
You don't need to use multiple styles. What you need is to use alternate layouts and alternative menu layouts.
For alternative menu layouts in the html/componentname/category folder of your template make a new style with a unique set of names similar to the way blog already provides an alternative to category list in the article category layout folder. Also make a new xml file for each layout that you make, with a matching name.
When you create your menu item you will now get these alternatives along with your other normal choices. Just select the one you want.
Based on the learnings above here is my code for the /templates/mytheme/com_content/category/blog.php
And then in the Global Configuration > Article Manager Options > Category choose Blog as the override/ layout.
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
$pageclass_sfx = trim($this->pageclass_sfx);
// so pick it on the page class in menu item
if (isset($pageclass_sfx) && $pageclass_sfx != '') {
echo $this->loadTemplate($pageclass_sfx);
} else {
echo $this->loadTemplate('default');
}
I can add multiple elseif if something else is needed, or it will look for 'blog_' . $this->pageclass_sfx . 'php'. It is always beginning blog_ as thats coded into the com_content. The old blog i moved to blog_default.php and blog_default_item.php

joomla add view into another view

Im using joomla MVC and I want to build a form that has different tabs which are different sections of the form with inputs in it. There are some tabs that are common to other forms that I need to include.
I would like to be able to load this common content from a separate file or view so i dont have duplicate code, plus is easier when I need to do a change to the form so I dont have to do it in all the forms. It's like displaying a view inside another view.
Is there a way to accomplish this?
A Joomla! provides the loadTemplate method to views.
So if you're currently in a tmpl file loaded for layout edit (ie. tmpl/edit.php ) you can call $this->loadTemplate('tab1'); and Joomla! will load the tmpl/edit_tab1.php file in the same view as your edit.php.
In that same view if you wanted to include say tmpl/other_tab1.php you would have to temporarily set the layout to other, eg. in one of our components during the Run template we need a tab from the Edit template, so we use:
<?php $this->setLayout('edit'); // This is ugly
echo $this->loadTemplate('plan');
$this->setLayout('run'); ?>
To load a template from another view alltogether, I think you would have to temporarily over-ride the view value, load the template then restore the view. eg.
$jinput = JFactory::getApplication()->input;
$jinput->set('view', 'other');
$this->loadTemplate('tab2');
$jinput->set('view', 'original');
NB: this last bit I haven't had time to test but it should work.
You can load a different template file for a different view manually, by simply requiring it. The following is for a view called "nameofotherview" with the layout "layoutname". If this is for an admin view use JPATH_COMPONENT_ADMINSTRATOR instead.
require(JPATH_COMPONENT_SITE . '/views/nameofotherview/tmpl/layoutname.php');
Remember that the data set up in the view class needs to be compatible with the main layout as well as the layout you're loading from elsewhere.
A side effect of doing this is that template overrides won't work. The loadTemplate function is doing a require but it checks the template paths for overrides first.
You can use vews in other views as described in Joomla documentation: Sharing layouts across views or extensions with JLayout

Question on using content from other cshtml pages in razor

I've read a couple of articles on using asp.net mvc3 razor (which I am fairly new to). I have a couple of .cshmtl pages which are like shared content (e.g. header). They are basically just html pages with one or two divs etc.
To embed this in my main page, do I just use #renderPage("page address"). Do I also need a call to #renderbody? Do I need to specify the/a page in the layout property?
Thanksa
I would put the common elements in a layout (or perhaps a partial view rendered by the base layout). In fact, that's what I did in an application I am now building and it works quite nicely. The one issue is whether or not you need View Model data populated by the controller and passed to that partial view. I did, so I used a base controller and populated the common elements in the view model (all of those also inherited from a base class that had the common properties) and used sections and then in the sections renderered the partial view or not, depending on the view's need.
You can create a Partial View for each of these and call:
#Html.Partial("ViewName")
Or you can use sections, or this article on sections might help too.
As you may or may not know, ASP.NET accepts HTML tagging.
So why not include your .aspx file with the HTML include tag?
Here's how:
<!-- #include virtual="path to file/include-file.html" -->
Ex:
<!--#include virtual="header.aspx"-->
I do this all of the time when writing an ASP.NET website.
Just place it wherever you want the code, from the included page, to show up.

dynamically render partial view on _layout.cshtml mvc 3

I want to display different navigation links based on the page that is loaded in my _layout.cshtml file.
I thought about checking the url and just calling Html.RenderPartial within an if block but that seems clunky.
Is there a way to control this with a controller?
If you truly need different navigation links on different pages then I think you should specify different layouts pages on these separate pages. These different layouts should then specify your _layout as their layout, making it the master layout
Ex:
_navlinks1.cshtml
#{
Layout = "_layout"
}
#RenderBody()
#section navlinks
{
#*create navlinks specific to current page*#
}
Then in your _layout page you can put #RenderSection("navlinks", false) where you want the navigation links to go.
But, if for some reason you need a distinct set of navigation links for every single page, then putting navigation links in your layout might not make sense. Might be better off having all your models inherit a base model with a list of items containing navigation link data. Then call a partial view that processes this data into the correct links in your views.

Custom section/category viewing in Joomla

I have written some modules to have it look nicely. What I need now is to re-order Joomla's standard viewing of the content. I have looked into com_content, and my first idea was to write my own component for it. But now I realized it would be about 90% a copy of com_content.
The problem is: When you open a link to a section, com_content views a list of the categories. But I want a list of the articles in category News of each viewed, and a link to every article in category Infos on the menu to the left. And of course, view each on click.
Is there a way to achieve that without writing an own component? Or would it be advisable to customise com_content to my needs? I want this done with a minimum of fuss and complexity.
You can override components view-templates in your theme.
In your case, for articles: Articles are part of the content component. components/com_content/views/article/tmpl/default.php is the default view of an article.
To override it copy the file to templates\<yourtheme>\html\com_content\article/default.php.
As an example, see the default theme ja_purity or beez, which also override it.
That way, you will only change the layout and only for your theme. The component will stay in tact and updates will not be as complicated as otherwise.
The visible components on your website are called modules. See the modules section in the admin section. The category-view is one of the default modules. There is also a module to display a list of categories (AFAIK). That is what you want, right? The modules listed in the module section are not all available ones, but all that are created. You can create a new one and set its type to the category-list for example, and define in what block of the theme it should display.
If you want to do your own Module, do so. Code it, then add it in your admin section and you’re done.

Resources