Custom HTML in Joomla Template Manager - image

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

Related

joomla 3+ get parameters from module and output them

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.

Including SVG contents in Laravel 5 Blade template

What is the best way to include the contents of an SVG file (located in the assets folder) in a Laravel 5 blade template?
I don't want to use image/object/embed tags, this should be an inline SVG for reasons of speed.
I know I could use <?php file_get_contents("file.svg") ?> but is there a better way specific to Laravel/Blade?
Edit: to clarify, the method should work with all SVG files, including the one below.
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg">
<path stroke="red" fill="#00f" d="M10 10h100v100H10z"/>
</svg>
Similar to the accepted answer but a bit cleaner (imo).
Use the laravel directive to extend blade, like so (in your App Service Provider, as outlined here):
\Blade::directive('svg', function($arguments) {
// Funky madness to accept multiple arguments into the directive
list($path, $class) = array_pad(explode(',', trim($arguments, "() ")), 2, '');
$path = trim($path, "' ");
$class = trim($class, "' ");
// Create the dom document as per the other answers
$svg = new \DOMDocument();
$svg->load(public_path($path));
$svg->documentElement->setAttribute("class", $class);
$output = $svg->saveXML($svg->documentElement);
return $output;
});
Then use it in your blade like so:
<div class="Login__image Login__cloud">
#svg('cloud.svg', 'Cloud')
</div>
This works, that's the simplest way I could think about :
{!! file_get_contents('images/icon.svg') !!}
Why not place the svg into a blade template?
resources/views/icons/dashboard.blade.php
then add in your views using blade syntax?
#include('icons.dashboard')
View Composer Method
I ended up using a view composer in a service provider.
In the service provider's boot() method:
// Wildcard view composer
view()->composer('*', function($view) {
// Instantiate new DOMDocument object
$svg = new DOMDocument();
// Load SVG file from public folder
$svg->load(public_path('images/logo.svg'));
// Add CSS class (you can omit this line)
$svg->documentElement->setAttribute("class", "logo");
// Get XML without version element
$logo = $svg->saveXML($svg->documentElement);
// Attach data to view
$view->with('logo', $logo);
});
And in my view:
<!-- Echo unescaped SVG content -->
{!! $logo !!}
I am using DOMDocument as it allows me to remove the XML version element which should not be in the HTML.
The CSS class is not essential but saves me wrapping the logo with another HTML element for styling.
If you only need the logo in a specific Blade partial such as header you could write
view()->composer('header', function($view) {});
http://laravel.com/docs/5.0/views#view-composers
https://laracasts.com/series/laravel-5-fundamentals/episodes/25
Blade Partial Method
This method is not best practice since this sort of code should not really be in a view. However it is very simple and much better than adding PHP code in every single view.
Make a new partial (lets say logo.blade.php) with the following code:
<?php
// Instantiate new DOMDocument object
$svg = new DOMDocument();
// Load SVG file from public folder
$svg->load(public_path('images/logo.svg'));
// Add CSS class (you can omit this line)
$svg->documentElement->setAttribute("class", "logo");
// Echo XML without version element
echo $svg->saveXML($svg->documentElement);
?>
You can now use the SVG image in a blade template by including the partial like so:
#include('logo')

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..

how to upload multiple image in my backend component joomla form

I am developing a component in J! 2.5 and want to add a browse button on the backend so the user can pick a file they have previously uploaded but when I use a media type in the form.xml I can upload only one picture.
I use the code below in a xml file but I can upload only one picture?
How would I go about this?
<field name="image"
type="media"
label=""
description=""
class="inputbox"
/>
In your XML you have to define new element
<field name="image" type="myelement" label="" description="" class="inputbox" />
Now create file models/fields/myelement.php If you use XML file to load form from models/forms/myform.xml it will be found automatically. If not add attridute to <fieldset> parent element
addfieldpath="/components/com_custom/models/fields/"
Now in that file create class.
<?php
defined('_JEXEC') or die();
jimport('joomla.html.html');
jimport('joomla.form.formfield');
class JFormFieldMyelement extends JFormField
{
public $type = 'Myelement';
public function getInput()
{
}
}
Now return whatever you want. You can incorporate any 3d party uploader. For examples what to return in getInput() start typing JFormField and you will see in dropdown available classes.

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.

Resources