I have a Views folder that has a pageBaseType of Class1 specified in the web.config. In my Areas/MyProject/Views folder I have a web.config that specifies pageBaseType Class2. MyProject is incompatible with class1.
There is a Views/Shared/EditorTemplates/String.cshtml file that's needed everywhere else in the system except for MyProject. Because String.cshtml uses Class1, and MyProject can't it causes errors.
Is there a good way to prevent the inheritance of the EditorTemplates folder in MyProject? I can copy paste the entire contents of EditorTemplates into MyProject/Views/Shared, and that stops it, but I don't want to have to remember to copy files every time we add a new cshtml to EditorTemplates.
What is it that your string editor template does?
If you need to render a specific template for a model property you can use the [UIHint] attribute or the [DataType] attribute. It would be better to do this if you don't intend for it to be used globally. Note that you will need to change the template name to something unique e.g. MyStringTemplate.cshtml.
Based on your comment, that you wish the editor templates to be global but not use them in your Area, my suggestion is to not use #Html.EditorFor(...) in your views, and instead create the form fields explicitly e.g. #Html.TextboxFor(...).
Related
I am having a little trouble here with a Magento installation here, which I "inherited" from a company who did some pretty heavy customizations to the theme.
I tried to rationalize most of the changes and was pretty successful with it. The problem is now, that I have some template files which have only one line of change.
In this specific case for example it would be a <button> that is now an <a> link. This is pretty much only one line in a 300 line template file.
Similar problems occurred with layout files of extensions. They have ONE dirty line in there, which for example resets the whole layout.
I then need to overwrite the complete layout XML file in the design, just to make a little change in one line, because those layout files are either overwritten or not. There is not merging process involved.
I took a look into the designer's documentation of Magento, but could not find anything useful.
I know that I could do some specific layout changes in the "local.xml" in my design, but those are more or less "contextless", which is not that great if those changes do belong to a certain extension.
Do you know a way to apply little template changes like mentioned in the first half or partially layout file overrides?
My main goal is to keep the files automatically updatable, which pretty much means: Download the module, replace files, done.
No manual updates to any overwritten files.
Use the "inherited" template as default template in a new package and add a child template with your changes. Example:
app/design/frontend/[package_name]/default - here will be the "inherited" old template
app/design/frontend/[package_name]/[your_child_template] - here will be your new child template
skin/design/frontend/[package_name]/default - here will be the "inherited" old template
skin/design/frontend/[package_name]/[your_child_template] - here will be your new child template
Partially layout file overwrides can be done for all pages or extensions in one local.xml file. Example:
app/design/frontend/[package_name]/[your_child_template]/layout/local.xml
If you want to add changes for a certain extension just add the extension xml file in your template folder. It will be the last one rendered and will wthe original. Example for the checkout cart page:
app/design/frontend/[package_name]/[your_child_template]/template/checkout/cart.phtml
For a small change inside a phtml file like your button example you will have to overwrite the whole phtml file. There is no way in Magneto to overwrite just a part of a phtml file.
I'm new to joomla development, but I can't seem to figure out how to dynamically fetch descriptions to be displayed as tool tips for the form data of a module backend. I'm looking at an example module from joomlart and their code for a single field element in their xml file looks like this.
<field
name="mainWidth"
type="text"
default="auto"
size="5"
label="MAIN_WIDTH"
description="MAIN_WIDTH_DESC" />
MAIN_WIDTH and MAIN_WIDTH_DESC are obviously variables that are somehow being accessed and rendered later when the module is run in the backend but I can't find where the values to these variables are stored or how to replicate this behavior. Any help would be appreciated.
Label is the label that prints to screen, and description is rendered as the tooltip.
You can just replace these variable names with the actual text and it will work when the form is rendered.
However, in your example, I believe they are using language files to get the text to display.
Whilst you can set a language file within your module for that module's use, naming convention suggests to me that these are being pulled from somewhere like the template's language file.
( Such a file is likely to be found either under /language or /administrator/language or /templates/yourtemplate/language )
The benefit of such files is to allow for translations of the site to exist without having to write a new module / template each time.
Ultimately, if you don't want various language versions of your site, and you only intend to use the module on one site and not sell it as an extension, then there is no strong need to create a language file for your own bespoke modules (though best practise would probably be to do so).
I'd like to know if it's possible to add an additional view override to my Joomla 2.5 Template without having to create an entirely new MCV model.
For example.
Currently I have an override for the categorylist. But I'd like to make another override for the categorylist and for that to work it'd need to be an available option in the backend aswel.
So I'd be able to choose between something like:
- categorylist
- categorylist-2
So say the override file is default.php, is it possible to add a default2.php and somehow make it available in the backend, or can I only do this by copying an entire com_content view and changing it so it's a new MVC model?
I had never tried this before, but on testing it did get this to work in a way. I'm not sure if this is exactly what you are looking for, but it should help. With this method, you would be able to create a menu item that links to this view.
Say you were wanting to create a new category layout. You already have overridden the default layout in your template as such templates/your-template/html/com_content/category/default.php and now you want a second version.
Make a copy of default.php and rename it default2.php. Then copy the default.xml file from components/com_content/views/category/tmpl/default.xml to templates/your_template/html/com_content/category/default.xml and rename this to default2.xml.
Open default2.xml and edit the title attribute of the layout tag at the top.
Go to the menu manager and add a new menu item and you should see your new title in the list!
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
I've got an editor template location in:
Areas/Posts/Views/Shared/EditorTemplates/Question.cshtml
I also have one in:
/Views/Shared/EditorTemplates/Question.cshtml
For both, the model is the same.
What i'm trying to do is within a View in the Posts area, call my editor template in the area, set some HTML and then bubble back up to the main shared editor template.
Here's the Posts EditorTemplate:
#model xxx.ViewModels.QuestionViewModel
#Html.Hidden("Id", (byte)Model.QuestionType)
#Html.EditorForModel()
But all it does it render out the hidden field, not the contents of the shared editor template.
If i get rid of the Posts editor template, the shared one is rendered properly.
I'm guessing MVC/Razor thinks this is recursive or something? Like im calling the same template?
Is there any way i can tell it to go to the shared one?
Essentially, i'm trying to re-use the HTML in the shared template, but inject some sneaky HTML of my own.
You can only have 1 template used at runtime for a given type. ASP.NET MVC first looks in areas shared templates folder and since it finds a corresponding template there it picks it up and it uses it. It then stops looking and the template you put in the main shared folder is never used. It's by design.
Is there any way i can tell it to go to the shared one?
Yes, you can explicitly specify the location of the template, but then it won't use the template in your areas folder:
#Html.EditorFor(x => x.Question, "~/Views/Shared/EditorTemplates/Question.cshtml")
As the HTML markup for the shared editor template was very simple (just rendered a checkbox and a label), i abstracted the markup into a custom HTML helper, then called this from both the shared template and my areas template.
~/Areas/Posts/Views/Shared/EditorTemplates/Question.cshtml:
#model xxx.ViewModels.QuestionViewModel
#Html.Hidden("Id", (byte)Model.QuestionType)
#Html.QuestionCheckBoxForModel()
#Html.QuestionLabelForModel()
~/Views/Shared/EditorTemplates/Question.cshtml:
#model xxx.ViewModels.QuestionViewModel
#Html.QuestionCheckBoxForModel()
#Html.QuestionLabelForModel()