Including css files through getDocument doesn't work - joomla

I'm trying to include some css files through $document = JFactory::getDocument(); or through JHtml::stylesheet($stylesheet); but none of this works. Why it's not working ?
$document = JFactory::getDocument();
$reset = '/media/com_event/css/reset.css';
$document->addStyleSheet($reset );
JHtml::stylesheet($reset);
I'm adding this files in component's view.

You need to include the full path using JUri::root() like so:
$reset = JUri::root() . 'media/com_event/css/reset.css';
$document->addStyleSheet($reset);
Hope this helps

Include in your template's index.php
<jdoc:include type="head" />
And it will start working.

Related

\PhpOffice\PhpWord issue converting HTML to DOCX

Thank you in advance
i want to convert HTML into DOCX so i used \PhpOffice\PhpWord library in laravel
The code for the same is as below
$html = "<html><body><h1>HELLO DEMO</h1></body></html>";
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$phpWord->save(public_path('temp/demo.docx'), 'Word2007');
instead of saving the docx, it is showing the HTML on the webpage.
I want to save into a folder
is there anything missed by me, i used this in laravel so require_once "vendor/autoload.php"; might not be required?
You need the
require_once 'vendor/autoload.php';
also add and change
$path = public_path('temp/demo.docx');
$phpWord->save($path, 'Word2007');

laravel blade include files with relative path

In laravel blade system when we want to include a partial blade file we have to write the full path every time for each file. and when we rename a folder then we will have to check every #include of files inside it. sometimes it would be really easy to include with relative paths. is there any way to do that?
for example we have a blade file in this path :
resources/views/desktop/modules/home/home.blade.php
and I need to include a blade file that is near that file :
#include('desktop.modules.home.slide')
with relative path it would be something like this :
#include('.slide')
is there any way to do this?
if someone still interest with relative path to current view file, put this code in the boot method of AppServiceProvider.php or any provider you wish
Blade::directive('relativeInclude', function ($args) {
$args = Blade::stripParentheses($args);
$viewBasePath = Blade::getPath();
foreach ($this->app['config']['view.paths'] as $path) {
if (substr($viewBasePath,0,strlen($path)) === $path) {
$viewBasePath = substr($viewBasePath,strlen($path));
break;
}
}
$viewBasePath = dirname(trim($viewBasePath,'\/'));
$args = substr_replace($args, $viewBasePath.'.', 1, 0);
return "<?php echo \$__env->make({$args}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
});
and then use
#relativeInclude('partials.content', $data)
to include the content.blade.php from the sibling directory called partials
good luck for everyone
you need to create custom blade directive for that, the native include directive doesn't work like that.
read this page to learn how to create custom blade directive :
https://scotch.io/tutorials/all-about-writing-custom-blade-directives
\Blade::directive('include2', function ($path_relative) {
$view_file_root = ''; // you need to find this path with help of php functions, try some of them.
$full_path = $view_file_root . path_relative;
return view::make($full_path)->render();
});
then in blade file you can use relative path to include view files :
#include2('.slide')
I tried to tell you the idea. try and test yourself.
There’s now a package doing both relative and absolute includes (lfukumori/laravel-blade-include-relative) working with #include, #includeIf, #includeWhen, #each and #includeFirst directives. I just pulled it in a project, it works well.
A sleek option, in case you want to organise view files in sub-folders:
public function ...(Request $request) {
$blade_path = "folder.subfolder.subsubfolder.";
$data = (object)array(
".." => "..",
".." => $..,
"blade_path" => $blade_path,
);
return view($data->blade_path . 'view_file_name', compact('data'));
}
Then in the view blade (or wherever else you want to include):
#include($blade_path . 'another_view_file_name')

How can include component js after templete js

I added javascript on templete index.php
$doc = JFactory::getDocument();
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.js', 'text/javascript');
and added another on component below
$document = JFactory::getDocument();
$document->addScript($this->baseurl . '/templates/' . $this->template . '/js/validation.js');
but always js (validation.js) of component getting add before tempelete js(jquery.js)
How can i add component js(validation.js) after templete js(jquery.js).
If you are using jquery.js as main jQuery library on your project then you can simple include the jquery.js before the head module in index.php. like below.
<script src="templates/js/jquery.js" type="text/javascript"></script>
<jdoc:include type="head" />
Then in your component you can simply use same as below.
$document = JFactory::getDocument();
$document->addScript($this->baseurl . '/templates/' . $this->template . '/js/validation.js');
An alternate option is Addcustom tag , helps to adding scripts to the document.
$document = JFactory::getDocument();
$document->addCustomTag('<script src="'.$this->baseurl . '/templates/' . $this->template . '/js/validation.js" type="text/javascript"></script>');
Otherwise you have to load the component js also in index.php with second order but that will load the js file for all pages.
Hope its helps..
I am going through google and found one solution that i can use custom tag function for component like below:
$document = JFactory::getDocument();
$document->addCustomTag('<script src="'.$this->baseurl . '/templates/' . $this->template . '/js/validation.js" type="text/javascript"></script>');
and for template as it below:
$doc = JFactory::getDocument();
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.js', 'text/javascript')

Change Codeigniter url

I'm using Codeigniter.I want to set href attr to something like :
<a href="/contact.html" >Contact</a>
But i get 404 error because i should write
Contact.
Where is some thing to fix this problem.
Any help please.
Assuming that you have a controller by the name Contact and you successfully extend the CI_Controller class, go to application/config folder and in config.php find:
$config['base_url'] = 'http://www.youdomain.com/';
Then in your internal links you should do:
Contact
If you are using javascript to make the redirect, put on top of the js file:
var host = 'http://www.yourdomain.com/';
Again:
window.location.href = host + 'contact';
If you're using codeigniter, you do not want to point to an .html file.
If you're using codeigniter correctly, you should use the helper methods that exist in codeigniter.
Instead of writing the anchor tag yourself, try this:
<?php echo anchor('contact', 'Contact'); ?>
to add the suffix to your controller in calling go to config/config.php and search for
$config['url_suffix'] = '';
and assign html to it to become
$config['url_suffix'] = 'html';

Magento - link to a frontend skin js file from an admin file

I'm already using jQuery in my frontend skin files. I've now added some extra functionality in an admin phtml file, that also needs to use jQuery. I don't want to have to include it twice, but how can I link to the existing jQuery file dynamically, assuming I don't know what theme package name is being used on the frontend (because obviously that can change, so I don't want it hardcoded)?
For example, I tried this, but it gives me the admin theme package name, not the frontend package:
<?php
// Get the package name
$configData = Mage::getStoreConfig('design');
$package = $configData['package']['name'];
?>
Anyone?
OK, this seems to be working. I can access the db directly, look for the "design/package/name" in the core_config_data table and then build the url to the js file using that:
<?php // Get the current theme being used, so we can build the url link to our jQuery file
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$tablename = Mage::getSingleton('core/resource')->getTableName('core_config_data');
$results = $connection->fetchAll("SELECT * FROM $tablename WHERE path='design/package/name';");
foreach($results as $row) { $theme = $row['value']; };
?>
<script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/'.$theme; ?>/default/js/jquery.min.js"></script>
for me helped to set $storeId as 1 not 0
$package = Mage::getStoreConfig('design/package/name', 1);
$theme = Mage::getStoreConfig('design/theme/default', 1);

Resources