joomla 3+ get parameters from module and output them - joomla

I have tried a few ways to do this but can't get any thing to work. My issue is that I want to pass a parameter from my module to a variable and output it in my html, through the default.php file.
Here is my config in the xml:
<config>
<fields name="params">
<fieldset name="basic">
<field name="prod_price"
type="text"
size="50"
label="Product Price"
description="Enter the product price" />
</fieldset>
</fields>
</config>
I think this is okay as it appears in the back-end.
My mod_helloworld.php file is simple and include a helper.php require, see below:
defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';
$hello = modHelloWorldHelper::getHello($params);
$mydata = modHelloWorldHelper::getMydata($params);
require JModuleHelper::getLayoutPath('mod_helloworld');
$document = JFactory::getDocument();
$document->addStyleSheet('modules/mod_helloworld/css/style.css');
$document->addScript('modules/mod_helloworld/js/test.js');
I think this is okay, the variables are all returning values.
My helper.php file is as below:
class ModHelloWorldHelper
{
public static function getHello($params)
{
return 'Hello, World!';
}
public static function getMydata($params)
{
return 'Hello, World! ';
}
}
I then echo these variable in my default.php and they output fine. What I think I need to do is to get the $params variable somehow and reference the prod_price but I can't seem to do it. I am a beginner with creating modules so excuse any obvious errors. If the getMyData function could collect the params then I could perhaps output them but I am not sure where to put code?
Kind regards,
James

suppose http://examples.com/index.php?prod_price=20
You can receive that data in your module via
$price = JFactory::getApplication()->input->get('prod_price',0);
it will receive post or get request.

Related

joomla templating custom JDOC statements

Which Joomla Platform / CMS class should I extend in order to make my own custom JDOC:include tags?
I would like to have custom JDOC tags like
<JDOC:include type="scripts" />
<JDOC:include type="scripts-body" />
and a bunch of other types.
You need to add new file at below location to add custom jdoc tag..
libraries/joomla/document/html/renderer/
File name should be same as the tag you are adding.. suppose you want to use scripts as tag then file name should be scripts.php
Now in this file you need to add below code. as tag name is scripts so class name should be JDocumentRendererScripts
<?php
defined('JPATH_PLATFORM') or die;
class JDocumentRendererScripts extends JDocumentRenderer
{
public function render($scripts, $params = array(), $content = null)
{
$contents = "";
//Do your work here
return $contents;
}
}
?>
Now you can use custom jdoc code <JDOC:include type="scripts" />
Hope this helps..

Custom HTML in Joomla Template Manager

While developing a Joomla Template, i got stuck on this question.
Every Joomla Module has a manifest. In that manifest you can set your Paramaters for your template with Field and Fieldset types. Is it possible to add a custom image in these sections? I tried CDATA for this but it doesn't work.
I've never tried this with a template, only a plugin and module, but I believe it's still the same concept.
Create a new folder in your template folder and name it "elements".
Then, in your template.xml file, find the <fieldset> that the parameter belongs to and add the following inside the tag:
addfieldpath="/modules/mod_social_slider/fields"
You now need to add a new parameter field like so:
<field name="image" type="custom" default="" label="" description="" />
Now, create a new PHP and place it inside your newly created "elements" folder and call it "custom.php". Then add the following code:
<?php
defined('_JEXEC') or die('Restricted access');
class JFormFieldCustom extends JFormField {
protected $type = 'Custom';
protected function getInput() {
return '<img src="' . JUri::root() . 'templates/your_template/images/image.jpg" alt="" />';
}
}
?>
Note that I haven't tested this so let me know if it works or not

How to add classes (e.g. lib) to a given Typo3 extension?

I got a (imho) minor noob question concerning writing of Typo3 Extensions (ver. 4.5 LTS). What I try is simply make up a little MVC class pattern which contains a small curl statement to retrieve information from a remote location. In principle, the MVC classes are already implemented and I just want to include them into the main procedure of my plugin extension. That was what I guessed to work:
class tx_uniklstudgangext2013_pi1 extends tslib_pibase {
public $prefixId = 'tx_uniklstudgangext2013_pi1'; // Same as class name
public $scriptRelPath = 'pi1/class.tx_uniklstudgangext2013_pi1.php'; // Path to this script relative to the extension dir.
public $extKey = 'uniklstudgangext2013'; // The extension key.
public $pi_checkCHash = TRUE;
/**
* The main method of the Plugin.
*
* #param string $content The Plugin content
* #param array $conf The Plugin configuration
* #return string The content that is displayed on the website
*/
public function main($content, array $conf) {
$this->conf = $conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
$view = t3lib_div::makeInstance('tx_uniklstudgangext2013_pi1_view');
// !HERE! : also tried with new(), since I don't want to deal with XCLASS here...
// this works: $content = "<p>Hello world!</p>";...the line below doesn't...
$content = $view->getCourseInfoOutput();
/*'
<strong>This is a few paragraphs:</strong><br />
<p>This is line 1</p>
<p>This is line 2</p>
<h3>This is a form:</h3>
<form action="' . $this->pi_getPageLink($GLOBALS['TSFE']->id) . '" method="POST">
<input type="text" name="' . $this->prefixId . '[input_field]" value="' . htmlspecialchars($this->piVars['input_field']) . '" />
<input type="submit" name="' . $this->prefixId . '[submit_button]" value="' . htmlspecialchars($this->pi_getLL('submit_button_label')) . '" />
</form>
<br />
<p>You can click here to ' . $this->pi_linkToPage('get to this page again', $GLOBALS['TSFE']->id) . '</p>
';
*/
return $this->pi_wrapInBaseClass($content);
}
}
I am a beginner in the Typo3 programming and I guess there are a hundred implicit issues I don't have in mind so far (by just not knowing how Typo3 operates implicitly). What I tried/did so far:
Disabling the template-cache globally by setting it up in the root template.
Conversion of all new statements into makeInstance(); not wanting this hookup to screw all my MVC code, I overwrote the called method $view->getCourseInfoOutput() by
public function getCourseInfoOutput() {
return "hello world!";
//return $this->_model->getTemplateByCourseId(5);
}
which leads me to the next issue: It just does not get the hello world within this! It seems, that Typo3 anyhow supresses the return value from classes out of the extension root class
When I put all the code successively into the main method, it worked out just fine
Could anyone please help me :/ I admit, that there is a slight possibility that I totally misunderstood how extensions work, but, as I said, I just want my code to run within the extension and simply return one single value. Is this really that hard?
Greetings & thx in advance!
$content is any HTML string. If you created the extension with the kickstarter or used any existing extension as boilerplate, then you just have to care about what happens inside you function.
This totally depends on you. TYPO3 will create your class and will call the main method and use the return value as content.
You can find all relevant docs at http://docs.typo3.org/typo3cms/CoreApiReference/ExtensionArchitecture/Index.html
You must of course not use any HTML inside your function. Your function must return the content as concatenate string with a return statement.
TYPO3 CMS uses ob_clean to flush the output buffer. If you forcefully output anything before TYPO3 CMS does, then you will break it.

can I use joomla's onAfterRender for a module rather than a plugin?

I want to insert some code to Joomla when any page is loaded.
For this I created a module that inserts code.
I am trying to use
<?php
// $Id: helper.php
defined('_JEXEC') or die;
jimport( 'joomla.plugin.plugin' );
jimport( 'joomla.environment.response' );
class modInsertCode
{
function onAfterRender($params)
{
$code = 'some code';
$documentbody = JResponse::getBody();
$documentbody = str_replace ("</body>", $code." </body>", $documentbody);
JResponse::setBody($documentbody);
return true;
}
}
?>
but JResponse::getBody(); returns an empty string. Any ideas, solutions of fixes to this code?
Thank you,
You have to do it using a plugin, you won't be able to do it using a module because the HTML response has not been generated by the time the code of the module gets executed.
I hope it helped!
I know this is a bit old but for future reference this can be done with jQuery:
$doc = JFactory::getDocument();
$js = 'jQuery(document).ready( function() {
jQuery("#module'.$module->id.'").appendTo(document.body);
})';
$doc->addScriptDeclaration($js);
This is assuming that you have wrapped the content in you module in something like the following, including the module id to support multiple instances of the module.
<div id="module<?php echo $module->id; ?>"> Your content </div>

Zend Framework: View variable in layout script is always null

I set a view variable in someAction function like this:
$this->view->type = "some type";
When I access this variable inside layout script like this:
<?php echo $this->type ?>
it prints nothing. What's wrong?
My application.ini settings related to layout
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.layout.layout = "layout" ; changed 'default' to 'layout'
Edit
This thread suggests the alternate solution, but looking for solution to above problem. And this was working in Zend 1.6.2. I just upgraded to 1.10 and it stopped working.
Edit
If I set this view var inside any _init Bootstrap function, it works.
If you want to assign something to your layout you have to go an other way:
// get the layout instance
$layout = Zend_Layout::getMvcInstance();
// assign fooBar as Name to the layout
$layout->name = 'fooBar';
I believe the layout view object and the action view object are separate instances of the Zend_View class.
I think this is the correct way to pass variables from the controller to the layout:
/**
* Controller action
*/
public function indexAction()
{
$this->_helper->layout()->assign('myName', 'John Doe');
}
and then in your layout script you can access the variables by referencing the layout object like this:
<html>
<body>
<?php echo $this->layout()->myName; ?>
</body>
</html>
Do you have the following entry in your application.ini file?
resources.view[] =
So, you can initialize the view with no options and use it through:
<?php echo $this->type ?>

Resources