issue with get url from menu id - joomla

I have the following code for joomla 2.5 ....
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$id = 474;
$link = JRoute::_($menu->getItem($id)->link);
?>
<script>
$(document).ready(function(){
var $link = $('<a>',{
class: 'all-news-link',
href: <?php echo json_encode( $link ); ?>
});
$('#custom-module .moduletable:nth-child(2) h3').append($link);
});
</script>
But it is not getting menu id 474 but 468 that is home page id. My SEF is also not turned on.

You should be able to just do this:
$link = 'index.php?Itemid=474';
Assuming that the location that you print it on the page is picked up by the system plugin that routes output all will be well.
If that is actually what makes it to the page, then you would want to route it manually:
$link = JRoute::_('index.php?Itemid=474');
The router will handle getting the link for you.

Related

Add php code in Gantry 5 template header

I am using Gantry 5 template and I want to add php code in the header. I set some variables using php and access them in the script tag. For example
<?php
$id = $user->id;
$name = $user->username;
?>
<script>
var id = '<?php echo $id; ?>';
var name = '<?php echo $name; ?>';
</script>
I want to add the above code in head of Gantry 5 template. In we just add the code in index.php but this mechanism is different in Gantry 5. How this code can be added?

Pagination on category home page

i have a blog where posts are shown in under different category id. In category home page i want to show 10 posts per page. But my pagination is not working. Can anybody help please?
//////////Controller///////
public function categoryDetails($category_id)
{
$data = array();
$this->load->library('pagination');
$config['base_url'] = base_url() . 'Welcome/categoryDetails/'.$category_id;
$data['total_rows'] = $this->WelcomeModel->select_number_of_published_blog_by_category_id($category_id);
$config['per_page'] = 2;
$this->pagination->initialize($config);
$data['allPost'] = $this->SuperEditorModel->select_all_blog_post_with_category($category_id,$config['per_page'], $this->uri->segment(3));
$this->load->view('frontend/master', $data);
You have to use create_links() function to load the pagination links. You can add it to your data array and pass it to the view
$data["pagination_links"] = $this->pagination->create_links();
$this->load->view('frontend/master', $data);
From the documentation:
create_links()
Returns: HTML-formatted pagination
Return type: string
Returns a “pagination” bar, containing the generated links or an empty
string if there’s just a single page.
add this in your controller to create pagination link
$data["links"] = $this->pagination->create_links();
And your view page where are you want to view pagination link
<?php echo $link; ?>

Joomla load module on extra place?

On my k2 pages I needed module complete on the top area, a module assign is not possible because the pages are dynamicly from the DB selected. So I installed a module like "loadmodule", the difference is simple I can get module with specific id.
For example: {loadmodulefromarticle|97} if I use it in the extra fields or in the content area then it works, but as written I need it in the top area of my page, so I have an if request and try load k2 content on the top. I get content and that's ok. But I see here only plain text and the module is not loaded. My question is, what is to insert here so that I get the module loaded? I think it can be something around to $result;
<?php
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '713') {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('introtext');
$query->from('#__k2_items');
$query->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
?>
<div id="gkHeaderMod">
<div><?php echo $result; ?></div>
</div>
<?php
}
?>
You could do something like the following. It uses Joomla coding standards to get the menu ID and renderModule to display the module.
<?php
$app = JFactory::getApplication();
$menuID = $app->getMenu()->getActive()->id;
if ( $menuID == '713' ) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('introtext')
->from('#__k2_items')
->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
echo '<div id="gkHeaderMod">';
$module = JModuleHelper::getModule( 'mod_example', 'Module Title' );
echo JModuleHelper::renderModule( $module );
echo '</div>';
}
?>
Note that you will have to change mod_example and Module Title to whatever you require

Render module in joomla

How do we render module in joomla with the title. Because now, I am able to render the module based on the position but it does not include the module title.
Here's how I render the module.
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('position-3');
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module->title);
echo JModuleHelper::renderModule($module);
}
?>
Many Thanks.
Try this,
Using this method you can pass parameters to the module .
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris"; //This is the way of passing params values
$Module->params = $Params;
echo $renderer->render($Module);
Hope it helps..
Try using the following:
foreach ($modules as $module)
{
echo $module->title;
echo JModuleHelper::renderModule($module);
}
You can also use the following, however you will have to manually enter the module title. This is only assuming you don't want it to be dynamic. You will also need to change mainmenu
$module = JModuleHelper::getModule( 'mainmenu', 'Module Title Goes Here' );
echo JModuleHelper::renderModule( $module );
Try this.
Hope this will work for you.
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = '';
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM `#__modules` WHERE id = 'your module id'");
$modules = $db->loadObjectList();
$module = $modules[0];
$contents = $renderer->render($module);

magento how to get Json Config by product id

I am in need to get the Json Config by product id or sku in the product listing page for a particular category.
I can see that getJsonConfig is decalred in Product options block where only one particular product is showing thats why it can show Json Config without saying the product id. But I am in product list page.
Is there any way to get it like below?
$this->getJsonConfig($productId);
$this->getJsonConfig()
The method is part of
class Mage_Catalog_Block_Product_View
and it calls
/* #var $product Mage_Catalog_Model_Product */
$product = $this->getProduct();
public function getProduct()
{
if (!Mage::registry('product') && $this->getProductId()) {
$product = Mage::getModel('catalog/product')->load($this->getProductId());
Mage::register('product', $product);
}
return Mage::registry('product');
}
So to use it ( in any other page ) you have to set product in the block instance as below :
Mage::register('product', $_product); // add the product object in the registry
$block = Mage::getBlockSingleton('Mage_Catalog_Block_Product_View'); // Instantiate the product view block
echo $block->getJsonConfig();
I found a simple solution for configurable product view page.
Hope that will help.
if ($_product->isConfigurable())
{ $block1 = Mage::app()->getLayout()->createBlock('catalog/product_view');
$block1->setProduct($_product);
$configPrice = $block1->getJsonConfig(); //var_dump( $config = $block->getJsonConfig`enter code here`() );
$block2 = Mage::app()->getLayout()->createBlock('catalog/product_view_type_configurable');
$block2->setProduct($_product);
$config = $block2->getJsonConfig();
}
<?php if ($_product->isConfigurable()): ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $configPrice ?>);
</script>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $config ?>);
</script>
<?php endif; ?>

Resources