how can I load a joomla module as a link? - joomla3.0

this is my problem...
I have some of images and links that I want to load different joomla modules when user click on them.
mean each hyperlink can load another module|position
thanks all

In case that you just want to call a module's content from a url the following answer will help you.
If you just want to show / hide a module in the same page you could use something similar to my previous answer: Joomla 3 Show different modules on same position depending on toggler
Joomla provides the functionality to call a specific file of the active template by adding the tmpl=FILENAME key/value to the url's query string.
All built-in templates have a component.php file if user wants to load the template with the component only. You could check the following link for more details: Adding print pop-up functionality to a component.
You could do something similar to only show the modules that you want to load.
You could copy the component.php to a new file (I have used custom.php) and added the following php code in the <body> ... </body> part.
<?php
$jinput = JFactory::getApplication()->input;
$selectedPosition = $jinput->getString("position", "");
$selectedModule = $jinput->getString("module", "");
$selectedModuleTitle = $jinput->getString("title");
if($selectedPosition !== "") {
$modules = JModuleHelper::getModules($selectedPosition);
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module);
}
} elseif ($selectedModule !== "") {
$module = JModuleHelper::getModule($selectedModule, $selectedModuleTitle);
echo JModuleHelper::renderModule($module);
}
?>
So with a similar way as loadposition / loadmodule works you could call the new template file using:
index.php?tmpl=custom&position=MODULE_POSITION
or
index.php?tmpl=custom&module=MODULE_TYPE
or
index.php?tmpl=custom&module=MODULE_TYPE&title=MODULE_TITLE
Optionally if you want to load the module with a specific style, you could pass it to the second paramter of the renderModule method like:
echo JModuleHelper::renderModule($module, array("style" => "xhtml"));
Hope this helps

Related

How to access Another Module's Content and Presentation Items after 2sxc v10.20+

Here is code that worked up through 2sxc 10.9.1. Though I am able to get the CmsBlock for the TabID, ModuleID and get that to .Render(), I need more. Here is the old code. Not sure it makes any difference, but this View is using the normal Link content-type and is running in an older version of the Content App (appx 3.03=ish). 2sxc has been upgraded and is now 11.22.0 LTS.
I have removed unnecessary stuff, so I doubt this runs as is...
#using ToSic.Razor.Blade
#using ToSic.SexyContent.Environment.Dnn7
#{
var Helpers = CreateInstance("_Helpers.cshtml");
// Display the items from the Manage Links module, we go in 'sideways'
// this gives us just the Content items with their Presentations settings, etc.
var sxci = Factory.SxcInstanceForModule(3360, 606); // ModuleID of Manage Links
var dyn = Factory.CodingHelpers(sxci);
var allLinks = dyn.AsDynamic(dyn.Data["Default"]);
}
#* other stuff *#
<div class="row co-documents justify-content-center align-items-center">
#foreach (var linkItem in allLinks) {
var linkInfo = Helpers.LinkInfos(linkItem.Link, linkItem.Window, linkItem.Icon);
string iconStyle = linkItem.IconStyle ?? "fas";
int linkColumns = (int)linkItem.Presentation.Columns;
string linkIconAlign = linkItem.Presentation.IconAlign;
string linkIconBGColor = linkItem.Presentation.IconBGColor;
#* other stuff *#
}
</div>
So the easy thing to figure out was how to get the module as a CmsBlock which I can Render() as is (below), but what I need to do instead is get proper access to the List of Content Items AND their Presentation data (like above, allLinks).
ToSic.Sxc.Dnn.Factory.CmsBlock(606, 3360).Render();
What am I missing? How can I get access to the other module's data like I was doing before? In this case, I do this in 3 different places on the website. So to outline this in English, I have a module that the client manages a few special links that get displayed in MegaMenus, other special nav, and directly on a couple of pages. In each place they render differently. In their "home" module, where they get edited, they just look boring like this:
I realize its something like this:
var allLinks = something1.AsList(something2.Data["Default"]);
I understand that something2 is an app instance, but how do I create it in the context of the other module?
And what is something1 nowadays? And how do instantiate it? Looks like its a new ToSic.Sxc.Code.DynamicCode() but I can't figure out how to construct that in a way that I can use or doesn't just throw errors.
Thanks in advance for any insight!!
Okay, it took a little testing, trial and error. And also I missed that DynamicCode() was a Method of the Factory class. In retrospect it does seem easy now.
So first you get the BlockBuilder
var block = Factory.CmsBlock(606, 3360);
Then you get the DynamicCode instance (Code.DnnDynamicCodeRoot) from that
var dc = Factory.DynamicCode(block);
And then things are normal
var allLinks = AsList(dc.Data["Default"]);
The rest of the code works like it did before; I can foreach through the links with Header (renamed from ListContent) and Presentation (now Content.Presentation) working just as expected.
The above answer works fine if you are inside the C# Razor template of the 2sxc View. But what if you are outside, for example in a Razor template for a DDR Menu?
Same two steps as above (get the block and the dc), but then you do NOT have access to AsList() or the App. Thankfully, you already have DynamicCode, so you could just get all the records in the Bibliography content-type like this:
<ul>
var items = dc.AsList(dc.App.Data["Bibliography"]);
foreach (var item in items)
{
<li>#item.EntityTitle</li>
}
</ul>
So once you've got your dc you've got access to all the usual 2sxc toys.

Add microdata to a Drupal site

Is there a way to add microdata to a Drupal 7 site by editing the field.tpl files? My site is built using panels and views so http://drupal.org/project/microdata isn't working. Is there another way to go about adding microdata by hard coding?
Thanks.
The best way to add microdata is by editing the field.tpl files and then checking - use file templates on views. For panels I used the module http://drupal.org/project/panels_extra_styles to add coding around the pane.
I managed to override the page template file and wrap my panel in a code.
The code I used was
template.php:
function ThemeName_preprocess_page(&$vars) {
// if this is a panel page, add template suggestions
if($panel_page = page_manager_get_current_page()) {
// add a generic suggestion for all panel pages
$variables['theme_hook_suggestions'][] = 'page__panel';
// add the panel page machine name to the template suggestions
$variables['theme_hook_suggestions'][] = 'page__' . $panel_page['name'];
$object = $panel_page['contexts']['argument_entity_id:node_1'];
$result_array = get_object_vars($object);
$value = $result_array['restrictions']['type']['0'];
if($panel_page['name'] == 'node_view' AND $value == 'product' ) {
$vars['theme_hook_suggestions'][] = 'page__node_view_product';
}
if($panel_page['name'] == 'node_view' AND $value == 'artist' ) {
$vars['theme_hook_suggestions'][] = 'page__node_view_artist';
}
and I created a files under ThemeName/templates
page--node_view_artist.tpl.php and
page--node_view_product.tpl.php
I hope this helps someone, it took me a long time to figure it out!

bread crumbs for views drupal 7

Am working with views and am wondering if there is a way to get the view to update the breadcrumb trail. When on my first view called homme the breadcrumbs are not updated it still just says "home >" as if it is still on the homepage. When I click a post the breadcrumbs update to "Home › Blogs › admin's blog › ". I need it to say Home > Homme > Name of Article, basically what you would expect when going to a blog site or post.
Can I get the view to act like a blog?
One option is to try overriding the themeable output generated by the default breadcrumb function.
Assuming you've created your own theme - create a file called template.php at the root of your theme. Create a function named YOURTHEME_breadcrumb, where YOURTHEME is the name of the theme. The HTML returned by this function will be the breadcrumb. Modify the return values as necessary here to get what you want. Consider using Drupal's menu functions to build a more satisfactory breadcrumb.
Check the comments of this API article for more detail: http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_breadcrumb/7
Adding this to your template.php file should work with d7 sites:
function theme_breadcrumb($breadcrumb)
{
if (substr($_GET['q'], 0, 13) == 'news/category') {
$breadcrumb[] = l('News', 'news/');
}
if (count($breadcrumb) > 1) {
if ($breadcrumb) {
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) ."</div>\n";
}
}
}

how do i include a tpl file in my module drupal 7

I'm building a module using hook_preprocess_node()
I've made a new view mode for the node entity called ´vacancy_teaser´ using the hook_entity_info_alter()
this shows up in my node display settings and view
so I want to use the template included in my module when this view mode is used.
my code:
/**
* Implements hook_preprocess_node().
*/
function vacancies_preprocess_node(&$vars) {
if($vars['view_mode'] == 'vacancy_teaser') {
$vars['theme_hook_suggestions'][] = 'node_vacancy_teaser';
}
}
my template file is called: ´node-vacancy-teaser.tpl.php´ but is not used in the output of my view
$vars['view_mode'] == 'vacancy_teaser' in the view. ( tested )
but where does $vars['theme_hook_suggestions'][] = 'node_vacancy_teaser'; looks for the template file? somehow it's not included / used.
apparently in drupal 7 useing dubble underscores is required for some reason.
node_vacatures_vacancy_teaser.tpl.php placed in the active template folder seems to do the trick... although I don't think this is a neat solution since the tpl.php file is separated from the module.
Be sure to specify the template file in the hook_theme implementation. The examples project is great for finding out the details of how to do things like this. Specifically, check out the theming_example_theme() function in the theming_example module…
function theming_example_theme() {
return array(
// …
'theming_example_text_form' => array(
'render element' => 'form',
// In this one the rendering will be done by a tpl.php file instead of
// being rendered by a function, so we specify a template.
'template' => 'theming-example-text-form',
),
);
}
Instead of appending to the end of the $vars['theme_hook_suggestions'] array, try:
array_unshift($vars['theme_hook_suggestions'], 'node_vacancy_teaser');
This will pass your suggestion to the front of the array, and it will be found first. Most likely since you are appending it to the end of the array, Drupal is finding an existing theme suggestion first and using it instead (such as node.tpl.php).

Drupal 7: Multiple pages for one node

We list events on our Drupal 7 site, but we'd like our users to be able to register for these events via a simple form. We're using Pathauto to generate URL aliases for events using the following pattern: events/[node:title]. We would like to have another page with the alias events/register/[node:title] which would present the registration form. We would also like to use tpl.php files for creating the templates, like we do for the rest of the site.
Any ideas on how we might accomplish this? Thanks.
You can try the Signup module. It's still in development, but over 7000 sites are using it:
I would put a register button on the event/ page via the node.tpl.php file. If all your nodes are not registerable, then you can check the node by getting the $nid with $node->nid and run a db_query on the url_alias table to see if current node qualifies.
<?php
$nid = $node->nid;
$result = db_query('SELECT alias FROM {url_alias} WHERE source = :source,
array(':source' => 'node/'.$nid));
foreach ($result as $r) {
$alias = $r->alias;
}
if (strpos($alias, 'events')) {
?> <input... or <button...
Have your register button redirect to events/register/$node->title page and make sure you pass the node. There's a few different ways to go from here. If you have questions about this part open another thread.

Resources