After upgrading to a new version of PHP (from 5.4.7 to 5.6.3) my Laravel Blade templates do not evaluate PHP code anymore.
For example I may have a file test.blade.php:
<? if(TRUE) echo "I am "?> {{1==1}}
Instead of outputting "I am true" the blade part is evaluated but the PHP code is not resulting in the following rendered output:
<? if(TRUE) echo "I am "?> true
I know there are specific Blade tags for control statements but this is merely an example. Does anyone know what's going on here? I don't really feel like rewriting all blade views to be PHP-less.
Shorttags are disabled by default in later PHP versions. Can't believe I missed that!
Related
I am working with WooCommerce for the first time and I am currently implementing WC filters on the shop page. The filters show up but are not functional, and the console is throwing the following errors:
ERROR 1: woocommerce_shared_settings filter in Blocks is deprecated. See https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/docs/contributors/block-assets.md
ERROR 2: deprecated.min.js?ver=932d8bb37da8bbb396a7a3f754345e08:2 select control in #wordpress/data-controls is deprecated since version 5.7. Please use built-in resolveSelect control in #wordpress/data instead.
The errors disappear when I remove the filters.
I have located the file where the deprecated code exists. I also read the WC docs about how to fix the issue and it presented this code:
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
Package::container()->get( AssetDataRegistry::class )->add( $key, $value )
It doesn't say where to put this code, though. Where should I put it to solve this issue?
I have the same problem.
Which is the file you located?
Here also says you have to add, on the "client side", this code:
wc.wcSettings.getSetting( 'key' );
I'm trying to add a shortcode to my Wordpress site to pull a piece of data from a Google spreadsheet and drop it into a page. To do this, I'm trying to use Sheetsu. The php libraries for Sheetsu are managed through Composer.
I've got a working piece of standalone code, but when I drop it in functions.php, like this...
function do_sheetsu() {
require('vendor/autoload.php');
use Sheetsu\Sheetsu;
$sheetsu = new Sheetsu(['sheetId' => '8b297aa81110']);
$response = $sheetsu->search(['id' => '2.05.1']);
$collection = $response->getCollection();
echo $collection->get(0)->answer;
}
add_shortcode('sheetsu','do_sheetsu');
...it blanks my site. If I comment out the use Sheetsu\Sheetsu; line, my site comes back, but I get no output, and the error "PHP Fatal error: Class 'Sheetsu' not found" which I suppose makes perfectly good sense.
I know enough php to be able to break things, apparently, and my knowledge of Composer comes mostly from messing around with Flarum a little bit.
I'm sure I'm missing something obvious here, I'm guessing involving namespace declarations or something, but I can't put the pieces together.
I'm looking suspiciously at my composer.json file, as well—something doesn't seem right, but I'm not sure what to fix.
For the record, my composer.json, composer.lock, and vendor folder are in my theme folder with functions.php. My composer.json file looks like this:
{
"require": {
"emilianozublena/sheetsu-php": "^0.0.6"
}
}
and I'm not sure it should.
But what's more troubling is finding a way around that use Sheetsu\Sheetsu line that seems to totally break Wordpress...
Thanks for any help!
I assume here you have installed the package using command line running composer install or composer require emilianozublena/sheetsu-php.
You cannot use the use php keyword inside function. The use keyword must be declared in the outermost scope of a file (the global scope). Refer to this answer for more detail here
So, in this condition you can chain the namespace while instantiating your class. In our case new Sheetsu(['sheetId' => '8b297aa81110']) becomes new \Sheetsu\Sheetsu(['sheetId' => '8b297aa81110']);
Try this code below
function do_sheetsu() {
require('vendor/autoload.php');
$sheetsu = new \Sheetsu\Sheetsu(['sheetId' => '8b297aa81110']);
$response = $sheetsu->search(['id' => '2.05.1']);
$collection = $response->getCollection();
echo $collection->get(0)->answer;
}
add_shortcode('sheetsu','do_sheetsu');
i have used laravel shortcodes (https://github.com/webwizo/laravel-shortcodes) with success, it is a nice bundle.
the question is: is there any bundle like this for symfony 3.x?
what this essentially do is take formatted string like [myString] with some optional parameters like [myString param1="abc" param2="def" ...] from a rendered blade / twig and looks for a controller / function etc. to resolve "myString". it passes the params to the controller, and the whole [...] stuff is replaced with the returned output. and it is done recursivly, so the result may contain another [myString2 ...] and so on. this is very useful in CMS building.
does anyone know anything like this for symfony?
There is a bundle that looks exactly what you are searching for:
https://github.com/mweimerskirch/MWShortcodeBundle
I'm currently working on the translation aspect of an eZPublish5 website which will contain 4 languages : french, english, russian and chinese, with french as original language and locale fallback.
Translation of content in backend is working just fine but I'm struggling with translating template parts, which I have encapsulated in {% trans %} filters. I don't think it's directly related to a locale issue because {% trans %} tags are working with french, english and russian, but not in chinese.
To do so I used
php ezpublish/console translation:update --output-format=xlf locale bundle --force witch generated messages.fr.xlf, messages.en.xlf, and messages.ru.xlf.
When in chinese, if I dump the locale in twig using {{ app.request.locale }} I get zh_TW for result, so I generated a messages.zh_TW.xlf, without any result.
After a loooong web search regarding language codes of all sort, I started losing patience and generated :
messages.chi.xlf
messages.chi-TW.xlf
messages.cn.xlf
messages.zh.xlf
messages.zh-tw.xlf
messages.zh_TW.xlf
to no avail.
This project is my first with eZpublish and I my first multilanguage under the Twig/Symfony logic.
Some code to show language declaration:
//ezpublish/config/ezpublish.yml
ezpublish:
system:
chi:
languages:
- chi-TW
- fre-FR
session:
name: eZSESSID
Any idea what am I doing wrong ?
Soooo.
I found a solution to solve my problem, and I'm quite ashamed to share it here.
-------Huge Revelation !-------
$php app/console cache:clear
The first three language files had been created quite a while ago and cache had been cleared a lot since, so that's why these trans files were working. I cleared the cache and now everything is working just fine.
BTW the answer to my own question was : messages.zh_TW.xlf
Now I'm gonna hide myself for a while.
I have these two file in my project that I am migrating from php. I have developed most of it by seeing the functionality but there are these two files which I don't know about. If somebody could have a look and help me converting these, I would really be thankful.
Menu.ctp
<?php
Configure::write('debug', 0);
echo($_GET['callback'].'(');
echo ($javascript->object($profiles));
echo(');');
?>
Retrieve.ctp
<?php
Configure::write('debug', 0);
echo($_GET['callback'].'(');
echo ($javascript->object($profile));
echo(');');
?>
Configure::write('debug', 0);
This tell application to put debug mode to off. If you in debug mode, any application error message will be displayed which is not appropiate for production or ajax call.
echo($_GET['callback'].'(');
$_GET is a global variable which hold all GET request parameter. For example, request to index.php?callback=some_callback will set $_GET['callback'] to some_callback.
echo ($javascript->object($profiles));
This is javascript helper in CakePHP which turn PHP array($profiles) into JSON.
echo($_GET['callback'].'(');
echo ($javascript->object($profile));
echo(');');
This will otuput : callback_parameter(JSON form of profiles);