joomla layout handling in custom component - layout

where do I set the desired layout in the following function if is getting called like
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'Myview'));
and I would like to be redirected for example to /views/tmpl/edit.php
found it
it needs to be declared by url structure

You can either use &layout=edit in the URL, or set it in the view using $this->setLayout('edit');

Related

OrchardCMS, how to set HTML title tag to page title

How does one dynamically set the HTML title tag on a page in Orchard?
I have a custom theme, and out of the box Orchard sets only the sitename as the page title.
looking in the Document shape, i see this
<title>#Html.Title(title, siteName)</title>
So for example, if my site is called "MySite" and my page is called "MyPage", the title should be
<title>MySite - MyPage</title>
There is another question that seems to deal with a similar issue, though it references a Title Override module as the answer. This module no longer works with newer/current versions of Orchard.
Alternatively, I've considered just using javascript to set the title, but
a) I don't know how to get a handle on the page title and
b) I don't know which shape in which I would do this
thanks in advance
#Html.Title is just a helper, for which you can find the source code here: https://github.com/OrchardCMS/Orchard/blob/6720b71cf3474a9a7b8a8cc9a99d58b1e733acfa/src/Orchard/Mvc/Html/LayoutExtensions.cs
As you can see, it takes a variable number of parameters. If you omit the site name in your call, it won't get output.
<title>#Html.Title(title)</title>
Note that you could also simply do <title>#title</title>.

Can I render all zones to an HTML string in a controller method

I'm trying to render the HTML for a content item to a string from within a controller action. Technically I just want to get the "body" part of it without any header/footer stuff. I want to do this so I can get a content item rendering the way I want once, and then display it as a normal orchard page OR by requesting the HTML for the content item via ajax to display it in a div in a JavaScript app. I don't want to have to manually render everything in the JavaScript as that would be duplicating the layout logic I already did. I want to re-use the bulk of the server side rendering so any changes are reflected in my normal orchard page and my JavaScript page. I've been digging into the code and searching everywhere and have gotten close but not all the way there.
I found these:
How to render shape to string?
Using FindView in Orchard
In my controller I have:
var shape = _contentManager.BuildDisplay(contentItem);
Using either of the two methods above, I can render that shape to an HTML string in my controller. All was golden. I was getting the body of that page and using it in JS. Then, I changed a placement file:
<Place Parts_Common_Body="Content:1" />
was changed to:
<Place Parts_Common_Body="/AsideFirst:1" />
The body moved where I wanted it (AsideFirst) in my normal Orchard page but disappeared from the HTML retrieved using the two methods above.
If I look at shape.Content.Items after the BuildDisplay call, I can see the item for the body is no longer there... why is it not rendering all the zones? Or, I guess a more specific question is why is the BuildDisplay method not building the complete shape? Is there a way I can make this work?
I tried a million different things and eventually got this working. Not sure I totally get it yet, but I think the problem had to do with the fact that I was using shape.Content and I'd moved stuff out of the Content zone. And maybe when I was looking at what the BuildDisplay method was returning I was just not looking at some newly created zone that actually did had the stuff I thought was missing. Clearly I need to learn more about zones and shapes... Anyway, I have a new zone called "MainInfo" now that I created in a placement file. I get a MainInfo property on the main shape returned form BuildDisplay and pass shape.MainInfo to the view rendering code and all seems to be working well now.

Add target property for dropdownnode in Widget Container

I would like to add a target (e.g. _blank) property for a basicLeafNode on the Widget Container from the extension library.
I do not see the property for this.
Instead I could use the onClick property and return an URL. But then I still would have no target defined.
I could add a postScript method
var target = url;
view.postScript("window.open('"+target+"','_blank')")
but this fires when the container is loaded.
Can I add a target property without using the onClick Property?
In case I use the onClick property what method should I use or how I prevent the postscript is executed when the container is loaded?
The basicLeafNode doesn't currently provide a target property. You have 2 courses of action:
implement your own custom node as Michael suggested (hard)
use a class on the link e.g. "newpageopen" and add an onPageReady script that selects all a elements with the calss newpageopen and add the target property to the resulted HTML.
Something like this:
require(["dojo/ready","dojo/query"], function(ready){
ready(function(){
dojo.query("a.newpageopen").attr("target", "_blank");
});
});
Hope that helps;
To make this list of solutions a bit longer here another on wich does not require dojo or jquery:
Instead of using your code as SSJS like:
var target = url;
view.postScript("window.open('"+target+"','_blank')")
You can use the Client Side Code and add SSJS code in #{javascript:}' wich i think is the shortest solution on this Problem. Here a hardcoded example:
<xe:basicLeafNode>
<xe:this.onClick><![CDATA[window.open('#{javascript: return "http://www.google.com";}','_blank');]]></xe:this.onClick>
</xe:basicLeafNode>
the above example will also work with viewScope variables or SSJS funktions:
<xe:basicLeafNode>
<xe:this.onClick><![CDATA[window.open('#{javascript: return viewScope.url;}','_blank');]]></xe:this.onClick>
</xe:basicLeafNode>
You can add the target attribute using JavaScript. It's kind of inconvenient way but would work.
You can use dojo.query to query the HTML output generated by basicLeafNode on the Widget Container. Once you get the node of <a> then you can add attribute using dojo.attr.
One problem you might face is that the ID generated by XPages contains the character :, which will not work so you would have to escape it.
function escapeColon(controlID) {
return controlID.replace(/:/g, "\\3A");
}
So your code would be something like:
dojo.addOnLoad(function() {
dojo.attr(dojo.query(escapeColon("#{id:ID_of_basicLeafNode}") + " > a")[0], "target", "_blank");
});
The code escapeColon("#{id:ID_of_basicLeafNode}") + " > a" would generate a CSS selector. Here I am assuming that basicLeafNode on the Widget Container would generate something like this <div id="_id1:basicLeafNode"><a href=".... So the CSS selector would search for a tag with that ID and inside it the <a> tag. You would have to modify this based on the output that is generated.
As I said its a bit inconvenient. Also I haven't tested this code.

display only the content of a page in lightbox2 in drupal

I am using drupal.I have to display the content of a page in lightbox2.(only the content not header,footer,menubar,sidebar etc).The url of that content node is http://mysite.com/node/1.
I have included the lightbox2 module and used the below code
<li>click here to see node content</li>
But the lightbox displays the whole page not only the content.i need only the text content.
One more option in that you can pass a parameter in get method for lightbox2 content.
Based on the parameter add condition in page.tpl.php
Not the best of the solution, but achievable.
Create a new page.tpl for node/1 and print only $content in this.
this way you will make sure you only get content and nothing else
I Agree with Vaibhav Jain, you can create a theme for the page without the header, left and right, footer. only the content and call that page inside the lightbox

Need to have separate "complete" Drupal theme for each page on a site

I want to build a Drupal demonstration site where I can create several custom themes and display each on a separate page of the site. Access can be either via links or menu items. The "simpler" the solution the better.
Create a custom block that executes PHP code. The following code snippet should show the current page in the theme set in $custom_theme.
global $custom_theme, $theme;
// If $theme is set, init_theme() will not initialize the custom theme.
unset($theme);
// Set the theme you want to use.
$custom_theme = "garland";
init_theme();
There is also a module that allows you to change the used theme based on some rules (in example, the content type being showed, the URL of the page being viewed, etc): the project page is http://drupal.org/project/themekey.

Resources