Laravel extend layout without Blade - laravel-blade

I want to extend default layout and add section for layout But I don't want to use Blade Syntax. As in phpstorm Blade syntax generates errors and IDE stop auto completion and also stop recognizing php tags at all(only after I use # symbol in action()).
So my question is how can I convert
#extends('layouts.default')
#section('content')
#stop
into php tags.

Looking at Laravel's source code (Illuminate\View\Compilers\BladeCompiler) it's:
#extends('layouts.default')
This is the trickiest part. Normally, when you use #extends Laravel compiles it to this: but adds it to a footer variable that's echoed at the end. If you add it at the end of your view instead of the beginning it should work too. (At least it worked in a simple test I did)
<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
#section('content')
<?php $__env->startSection('content'); ?>
#stop
<?php $__env->stopSection(); ?>
However if you're on PhpStorm 8, the Blade syntax is actually supported and I never had a problem with it. What's new in PhpStorm 8?

Related

AMP: External amp css using {%...%}

I keep seeing people say AMP pages must have the css code all inline in the custom tag, but on the website it seems to say you can reference it from an external file for when its from a preprocessor: https://www.ampproject.org/docs/guides/responsive/style_pages#using-css-preprocessors
Can someone tell me if I'm interpreting this wrong? Thank you!
{% include "/assets/css/main.min.css" %} is Twig Tag (The flexible, fast, and secure template engine for PHP). For more details Click Here
You can use like this if using PHP language
<style amp-custom>
<?php include("styles.css"); ?>
</style>
include : The include statement includes and evaluates the specified file.
Note : styles.css is external css

PhpStorm forcing file type

I have my script.php file in project. It contains javascript, but I wanted it to ne created dynamicly, based on server-side data.
I setted it's Content-type to text/javascript with php, but PhpStorm does not see it as javascript file. So I loose javascript syntax hightlighting, error detection, live templates...
How can I force PhpStorm to see that .php file as javascript file?
You could make a naming Convention for this type of file.
Something like
foo.js.php
bar.js.php
baz.js.php
And then go to Options ALT + F7, navigate to File Types, and register *.js.php to javascript
What you are trying to do sounds like bad practise.
You maybe want to have something like this:
A real JS File which is compileable by Closure Compiler or something like that, which provides "bootstrap" functions, which take your values as parameter.
And if you write this in your template.php, everything is fine for PHP Storm:
<script>
doFoo(<?= $myFirstValue ?>, <?= $myFirstValue ?>);
</script>
Maybe you can work with data attributes in Your HTML which i think is cleaner then inline script tag.
Also take a look here: https://softwareengineering.stackexchange.com/a/126678/122683
Settings | Template Data Languages
Find your file there and assign JavaScript in right column to it (or whole folder --then it will be applied to all files in that folder and subfolders).
This will tell IDE to use JavaScript instead of default HTML as outer language for that file.
You can use the <<<JS heredoc syntax to make PhpStorm highlight a specific part of your file as Javascript. For example:
<?php
echo 'This is using PHP syntax highlighting';
echo <<<JS
<script>document.write('This is using JavaScript highlighting');</script>
JS;
You can also use file-specific language injection with ALT+ENTER, also see http://blog.jetbrains.com/phpstorm/2013/06/language-injection-in-phpstorm/ for further details on that.
You can also use the built-in Language Injection of IntelliJ (which is the platform on which phpStorm is built). For that, just mark the part of your file then press ALT + ENTER and use "Inject Language/Reference".

How to make same layout for all web pages

I am currently working on HTML I want to ask a question about website development.I am developing a website in which the basic layout remains same like menu, side menu etc but only the content changes.Currently I have make separate .html file for all web pages.
Can any one tell me is there a way through which I can make a separate file having etc common to all and call it in my html file.I have heard about CSS but it will only change the style and layout.
thanks
If your HTTP (apache 2 and IIS do) server supports Server Side Includes then you can just include another HTML file :
<!--#include file="header.html"-->
your content
<!--#include file="footer.html"-->
no need for a server side language then - just plain HTML
This is very big topic to include in just one answer. SO I will give only the logical part.
Separate your template into multiple chunks like:
1. header.php
2. leftSidebar.php
4. rightsidebar.php
5. footer.php
Now, include these common part on your every page.
For example: index.php
<?php
include "header.php";
include "leftSidebar.php";
echo "<div>".$thedifferentpart."</div>"; //Change only this part on every other page you will create.
include "footer.php";
?>
NOTE: This is only a logical part, applying the concept on your code
Yes, your best bet is a server side language, as Adam said. Absolutely avoid using the old style html frames: they're deprecated, and cause a certain number of problems, both on the programming side and on google optimization.
By using a server side language, you'll still have entire pages, but they will be partially generated by php (or asp) by printing more files into one. For example:
http://www.php.net/manual/en/function.include.php
Bye!
Your best bet in the long term is to use a server side language like ASP.net or PHP
I don't believe that is possible, strictly through HTML. However, you could use server side scripting like PHP to get it done. What you're talking about is a template, and is used quite often. What you would want, is to have your menu items (and CSS) and your header/footer code in separate pages. This way, if you make changes to the menu, or header/footer, it would be reflected in all the pages (written with PHP) you have scripted with the template method.
You would need the menu.html, header.html and footer.html in a place accessible by your main page code. That is, you would use the template method to write the content of your pages.
A psuedo code example in PHP would be like such:
<?php
include('header.html');
include('menu.html');
echo "Your main content items here";
include('footer.html');
?>

Disable CSS stylesheet for a specific action in Symfony

Is there any way of disabling a stylesheet in view.yml for a specific action in Symfony?
For example I've got this in my view.yml:
default:
stylesheets: [default.css]
I want to be able to do something like:
displaySuccess:
stylesheet: [!default.css]
to disable default.css in displaySuccess only
Is this possible or do I have to explicitly say which modules/actions should have default.css?
You can remove or add stylesheets to a modules view.yml by doing the following:
displaySuccess:
stylesheet: [-default]
would remove default.css from the display action. Simply putting
displaySuccess:
stylesheet: [-*]
would remove all stylesheets.
to remove for example, unecessary /sfDoctrinePlugin/css/default.css, now you can overwrite the backend styles with your own!
maybe put it into yout layout.php:
<?php sfContext::getInstance()->getResponse()->removeStylesheet('/sfDoctrinePlugin/css/global.css'); ?>
<?php sfContext::getInstance()->getResponse()->removeStylesheet('/sfDoctrinePlugin/css/default.css'); ?>
I'm not 100% certain, but I believe the compiled view.yml file is processed before execution of the action. If that's true, you can do:
public function executeDisplay()
{
$this->response->removeStylesheet('default.css');
}
I find view.yml to be a little inflexible. You may find it easier to have a global "head" template that gets included in your layout(s). Then you can check sfConfig values to see if you should include individual files, making it easier to turn them on and off.

Load external script in <head> in Drupal 6

I want to load an external script in <head>. It is module specific so I want my module to take care of the loading.
In Drupal 6, function drupal_add_js() does not allow to add an external script in <head>. It will be available in Drupal 7 passing the "external" argument to the function. In D6, I can use drupal_set_html_head() instead, but it inserts the given data in the beginning of the <head> which I don't want. I'd like to append data in it.
It turned out that drupal_html_set_head() appends data.
$stored_head .= $data ."\n";
So the behavior I experimented--data was inserted in the beginning of head data--should come from that I call drupal_html_set_head() in my module's hook_init() function.
How can I append data to the very and of <head>?
The default page.tpl.php (you can find it in /modules/system/page.tpl.php is this:
<head>
<title><?php print $head_title; ?></title>
<?php print $head; ?>
<?php print $styles; ?>
<?php print $scripts; ?>
<script type="text/javascript"><?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>
When you make drupal_set_html_head() it is appending stuff to variable $head, but still there are more variables appended as you see.
One possible solutions is to append the stuff that you want to $scripts, instead of $head.
How?
with a preprocess function from your module:
function MYMODULE_preprocess_page(&$variables) {
$variables['scripts'] .= $your_stuff;
}
I didn't try this solution, but if doesn't work maybe is because the order of execution. Try to set your module's weight higher, so it will run after the system_preprocess_page.
Other reason why may not work is because the theme is printing the variables in different order in page.tpl.php. But you can't control this from the code of a module.
There are multiple solutions to work around the problem.
use hook_footer() to add the js to the footer
make a small jquery script, which creates the <script> element and adds it to <head>
do it with a template preprocess function
make your own page.tpl.php
Drupal uses the .= operator to create the $head variable. The $js and $css is kept in an array, and allows you to be re-orderd.
$head is a string, and cannot be re-orderd, othern then by ugly, error-prone hacks. Such as regular-expression explosions, re-ordering and imploding.
$heads = preg_explode("\n", $head);
ksort($heads);
$head = implode("\n", $heads);
in your theme's variable pre-processor.
Did you see this comment?
Beware when using this to set an external js file call in D6, eg:
drupal_set_html_head('');
If you don't include a full script closing tag (ie ), it will
break in Firefox (and possibly other browsers, webkit-based ones seem
fine). The tag will fail to close, and will wipe out any other headers
up to the next available tag. This usually results in all
your css files failing to load, plus the next fully-tagged js file. So
use this form instead:
drupal_set_html_head('');
This applies up to and including Drupal 6.16. You can overcome it in
D7 with the new external option in drupal_add_js.

Resources