eftec / bladeone Goto Github PK
View Code? Open in Web Editor NEWThe standalone version Blade Template Engine without Laravel in a single php file and without dependencies
Home Page: https://www.escuelainformatica.cl/
License: Other
The standalone version Blade Template Engine without Laravel in a single php file and without dependencies
Home Page: https://www.escuelainformatica.cl/
License: Other
in BladeOne.php, line 1531 the function "if" is defined. This causes an error on php 5.4
Hi, is it possible to use sub_folder/nested_sub_folder/view syntax with BladeOne?
Example:
$blade->run('employment.employee_wizard.index', [ 'titles' => $titles, 'gender' => $gender, // ... ]);
where employment.employee_wizard.index maps to the following:
VIEWS_DIR/Employment/employee_wizard/index.blade.php
After using the @parent update you previously pushed, I am now seeing this echo at the end of my DOM document:
@parentXYZABC
@parent
Show the original code of the section | REMOVED(*)
Unless there's a better way to handle this, here's an example of @parent
and why it's needed:
@section('js_bottom')
<script>
alert('Template JS');
</script>
@endsection
@section('js_bottom')
<script>
alert('form post js code');
</script>
@endsection('js_bottom')
When you overwrite the section, you lose one of the sections. From what I can tell, the first one sticks, the rest do not
.
If you were to add @parent back, the second one could "STACK" to the first, like so, giving you both alerts:
@section('js_bottom')
@parent
<script>
alert('form post js code');
</script>
@endsection('js_bottom')
$ok = @file_put_contents($compiled, $optimizedContent); if (!$ok) { $this->showError("Compiling", "Unable to save the file [{$compiled}]. Check the compile folder is defined and has the right permission"); return false; }
file_put_contents returns the number of bytes that were written to the file, or FALSE on failure.
So, here should use $ok===false. In BladeOne.php Line 404.
This folder should be added to .gitignore
Example code:
$bladeSource = <<<'BLADE'
@if($a == 4)
BLADE;
$this->blade->runString($bladeSource, ['a' => 4]);
This thows a ParseError
, but the output buffer is not properly cleaned.
Why do we need cache filename in format $fileName . ' _' . sha1($fileName)
?
sha1($fileName)
seems redundant because semantically it's the same with $fileName
(same filename will always result in same hash).I rewrote it to just $fileName . '.php'
(because it's basically a regular php files) in my project and it seemed more straightforward.
Hi,
You class BladeOne is amazing, but I have a question, how get baseurl through of a helper?
Twig for slim have the method called baseUrl(), how implement same helper?
example: link
Best regards
Hi,
I've updated from version 3.4 to version 3.7 without change nothing and the plugin won't load anymore. I'm using BladeWithLang. I've also try to downgrade to version 3.5 and the problem still persist. Version 3.4 is okay.
I'm delegating to Composer autoload the loading. So my situation is the following:
config.php file:
require_once ('../vendor/autoload.php');
MyBladeLang.class.php file:
use eftec\bladeone;
use eftec\bladeone\BladeOneLang;class MyBladeLang extends bladeone\BladeOne {
use BladeOneLang;
}
index.php file:
$blade = new \MyBladeLang($source, $cache, MyBladeLang::MODE_SLOW);
Since 3.4 this was working correctly. Can you explain me what am I doing wrong that stopped to load the class?
Thanks in advance,
Best Regards,
Hi. First of all - great job on single Blade class.
Today had an issue with foreach
loop when tried to loop through variable named $cancelReasons
.
Checked out compiled file and noticed that something strange was with foreach
.
As my variable contained as
string then compileForeach()
function using preg_match('/\( *(.*) *as *([^\)]*)/', $expression, $matches);
split incorrectly @foreach ($cancelReasons as $code => $reason)
part.
Don't know if this is correct way to fix it but changing preg_match
part to preg_match('/\( *(.*) * as *([^\)]*)/', $expression, $matches);
(added space between * as
) helped solve my issue.
Maybe there is better way solving this or at least this could help someone.
First! Thank you so much for making this functional :)
Sorry to report this, but it looks like "function compileStatements" is picking up @return tags which are created in PHP Comments.
Here's some code from the blade file. I am going to try to prevent this error from continuing, but if you have a way to fix / workaround correctly, please let me know.
Thank you!
Operation not defined:@return
<script>
/**
* Advanced calling object. You can specify custom functions to run at various
* points in the form submission process.
*/
var test = {
/**
* An example function that is run right before form is submitted via AJAX.
* @return void
*/
beforeSubmit: function ()
{
$.vine.log('Form is about to be submitted.');
},
Hi!
In "3.14" path you broke simple case of preparing templates.
I'm talking about these changes: http://i.imgur.com/wm6WnFP.png
Let's say we have simple class:
class ViewParser extends \portalbladeone\Base
{
public function __construct($templatesPath, $templatesCompiledPath)
{
$this->file = str_replace('.blade.php', '', $file);
parent::__construct($templatesPath, $templatesCompiledPath);
}
}
And if you try to do (new ViewParser('/path/to/templates/','/path/to/compiled/templates'))->compile('my_awesome_template', true);
, you will get error:
portalbladeone\Exception\BladeError: Read file : Template not found :
Since you deleted $this->fileName = $fileName;
part, $compiled = $this->getCompiledFile();
and $template = $this->getTemplateFile();
will get trash.
Also doesn't it do more sense to switch condition from if ($this->isExpired() || $forced)
to if ($forced || $this->isExpired())
I can make test and pull request to fix this.
Hi,
first of all I want to thank you for the project. I really think is a great plugin.
I have a little problem that i can't understand. I'm using bladeone with lang and I can't find a way to do something like this:
{!! ($var == 1) ? @_e('Link Name') : '' !!}
basically @_e('Link Name') always return me an error:
Parse error: syntax error, unexpected '<' in ...
I've also try '@_e('Link Name')' the error is:
Parse error: syntax error, unexpected 'Link' (T_STRING) in ...
Or: '@_e(Link Name)' in this case does not return an error but it prints:
_e(Link Name); ?>
Changeing to this:
{{ ($key == 1) ? '@_e(Link Name)' : '' }}
prints: < ? php echo $this->_e(Link Name); ?>
How can I have "Link Name" printed correctly with Lang ?
thanks in advence,
Best, Ar3s.
The current implementation of @inject
is not really usable for me right now. The fact that
@inject('myvar', 'NameSpace\MyClass');
Results in
<?php $myvar = new NameSpace\MyClass\myvar(); ?>
would require a custom autoloader which takes this into account and still returns te proper class and I'd rather not have custom resolving logic which might be unpredictable inside my autoloader. Or I would need to name my variables to have the same name as the class, which could result in other problems and is not behaviour I would expect when I see an @inject
statement.
I would like to be able to configure what happens when I try to inject a specific class. Something like the following
$blade = new BladeOne($views, $cache, BladeOne::MODE_AUTO);
// The default resolver would be
// function ($className) {
// return new $className();
// }
$blade->injectResolver(function ($className) {
// Custom logic for resolving
return IocContainer::get($className);
});
@inject('myvar', 'NameSpace\Singleton')
<?php $myvar = $this->injectClass('NameSpace\Singleton'); ?>
This would bring it closer to the functionality Laravel provides with @inject
, which tries to pull an instance from the app()
container.
To keep compatible with the current behaviour the injectClass
function could also pass the variable name.
Caching doesn't work when the caching directory doesn't exist, the templating engine can't save the file as file_put_contents fails.
This could be fixed by adding something like:
$dir = dirname($compiled);
if (!file_exists($dir)) {
$ok = @mkdir($dir, 0777, true);
if (!$ok) {
$this->showError("Compiling","Unable to create the compile folder [{$dir}]. Check the permissions of it's parent folder.", true);
}
}
before:
$ok = @file_put_contents($compiled, $contents);
in method compile().
For me this is neccesary as I have a software where you can install different themes and the caching directory is therefore flexible (cache/templates/).
BladeOne throws error when i use vue with blade
BladeOne Error [@compile]:
Operation not defined:@click
How can i exclude vue's @tag?
Hello, i have a problem with header content-type.
function sitemap()
{
header("Content-Type", "text/xml");
header("HTTP/1.1 200 OK");
$data['sitemap'] = my_sitemap();
echo $this->blade->run("sitemap", $data);
}
I check the sitemap validity, but it always return text/html.
i use @verbatim as:
@verbatim
sssssssss
@endverbatim
got:
BladeOne Error [@compile]:
Operation not defined:@__verbatim__
There are some Laravel dependencies, like calls to app()
or Illuminate
. As BladeOne usually only makes sense outside of Laravel environments, it doesn't make sense to keep them in the code. Therefore they should be removed.
The following snippet throws a parse error.
@includeIf("child_to_include", ["some_var" => $some_var])
Any ideas on supporting Markdown?
In Laravel we can install a package like https://github.com/andreasindal/laravel-markdown
but I don't think this would work for BladeOne
Hi!
I am using Your template engine with one of my new projects,
I am facing a problem, I can't add function output in every single in "bladeone" run() function.
eg. I have a footer its get the data from the database, and I have created a function to collect data from database and output an array, and I merge the footer in the template array.
But, is there a way I use @set($array=functionname('value'))
or an alternative method to define an array through function output in a template and include that template in main site footer?
Thanks,
I'm using responsive email's the CSS is direct in <head>
the problem I have is that:
@media [whatever] { /* CSS... */ }
So every time I try to send an html email it returns compile error because the @media is not defined... s, in order to "fix it" I had to remove my CSS media queries... but my emails doesn't look "responsive"...
Hi,
I'm looking testsecurity.php but I can't understand much.
How can I let blade know i'm authenticated or not? How does it work with bladelang?
thanks,
A.
Thanks for this project, I like how lightweight and straightforward it is.
I am currently using BladeOne to compile templates, which are then sent to a production server, which runs in BladeOne::MODE_FAST
. This setup uses git to make sure that only changed files get updated.
The current implementation of BladeOne uses uniqid
in the extends implementation. This causes each run of compile
/run
to result in a different file. Which in my case causes the file to be unnecessarily updated on my production server.
Would it be possible for compileExtends
to behave in such a way that it always returns the same output for the same input?
HI,
My code:
$blade->share('lang', $_lang); //(I want set variable lang global)
echo $blade->run('layout.banner', array('var1' => 'content1') );
File: /views/layout/banner.blade.php (Can't get the variable 'var1')
But remove line share() is working!
I do not know why?
Hi,
The class is great, but I can't see why the BladeOneCache.php file exists in the lib folder when the main class does not use it at all? Also no way to change the caching engine to memory or something else. The file caching logic is hard coded into BladeOne. Am I missing something or is it for some specific reason that the caching must be done in files?
The usage as mentioned under "using composer's autoload.php" is not working.
I am always getting error
Class eftec\bladeone\BladeOne does not exist
I've installed the package via composer. However, it works when I directly include the BladeOne.php file.
Hi,
I'm push 1 array from PHP via bladeOne.
I foreach it,
`
@foreach ($array as $item)
{{ $item->id }} (not working)
{{ $item['id'] }} (working)
Why?
Thanks!
I noticed that the last release note said this version is aligned with ver. 5.8, however I cannot find the method for aliasing included views. It was in ver. 5.7 as well, so it may be located under a different method name that I am unable to find.
To get a clearer understanding, this is what I am referencing:
Aliasing Includes
If your Blade includes are stored in a sub-directory, you may wish to alias them for easier access. For example, imagine a Blade include that is stored at resources/views/includes/input.blade.php with the following content:
<input type="{{ $type ?? 'text' }}">
You may use the include method to alias the include from includes.input to input. Typically, this should be done in the boot method of your AppServiceProvider:
use Illuminate\Support\Facades\Blade; Blade::include('includes.input', 'input');
Once the include has been aliased, you may render it using the alias name as the Blade directive:
@input(['type' => 'email'])
source : https://laravel.com/docs/5.8/blade#including-sub-views
Travis should be enabled on the repo now that a config is in place. This allows for automatic test running.
I understand that global variables are useful when you distinct dev and prod configurations (for example, you're passing constants from .env
files), but constants are defined once and kept the same for whole run time. For example, if you want to compile some of templates in one mode, and some in another, you will not able to.
If we had some sort of setMode( $mode )
that will prevail over constant if used, it would be more flexible.
The CSRF token field will not refreshed with a new value in the compiled view. Even when mode is set to MODE_SLOW
For an @extends('some.blade.file')
BladeOne compiles to
<?php $_shouldextend[{$this->uidCounter}]=1; ?>
...
<?php if (@$_shouldextend[{$this->uidCounter}]) { echo $this->runChild('some.blade.file'); } ?>
Which is not valid php.
In old version:
"eftec\\bladeone\\": "/"
and now :
"eftec\\": "vendor/eftec/"
In Usage section under composer example it says to use bladeone\BladeOne
class name. In fact composer will not find that class, you have to use eftec\BladeOne\BladeOne
instead.
Good day Team,
It's really a nice work been done here. This extension has really been helpful in my Codeigniter projects.
I just want to keep a tab on this Feature Request, and this link to an SO post
I'm willing to develop this feature, when I'm free, but I would really appreciate any brief explanation on how to go about it.
Thank you.
I was in Cuba working and the Internet is Cuba is practically nil. Now i have a lot of backlog accumulated. I will check those issues/fixes the next weekend.
See ya
It would be nice to be able to change the file extension for the template system from .blade.php to .html or somethin different. It is useful for me as I am having an existing system with hundred of existing templates.
Additionally, I think Laravel/Blade supports this, too?!
This is simple as introducing one attribute and a getter and setter for it and then use it in getTemplateFile().
The following code:
@switch($countrySelected)
@case(1)
first country selected<br>
@case(2)
second country selected<br>
@defaultcase()
other country selected<br>
@endswitch()
with
use eftec\bladeone\BladeOne;
use eftec\bladeone\BladeOneHtml;
use eftec\bladeone\BladeOneLogic;;
class Blade extends BladeOne{
use BladeOneLogic;
}
$blade = new Blade("/var/www/views","/var/www/tmp");
$blade->run("view")
retults in the following error:
Parse error: syntax error, unexpected ' ', expecting case (T_CASE) or default (T_DEFAULT) or '}' in /var/www/tmp/test _a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 on line 2
Hello, I'm trying have a variable available everywhere, in Laravel you'd go about this by using
View::share( 'success', $success );
View::share( 'errors', $errors );
Is there a way to implement this in blade, as i am trying to set my flash messages in the middleware/default controller (it is an old framework) and unset them from the session. I need this to be done once every time the page loads, hence why it is not ok to pass them with
$blade->run($path, $variables); everytime in every controller.
It seems asset() function is not in BladeOne yet. Is there any way to inlcude .css and .js files from under /public with BladeOne?
Is it possible to add Bladeone to the wordpress theme I'm developing?
I have installed it using composer and now I have vendor folder in my theme. I have added
require get_stylesheet_directory().'/vendor/autoload';
And I'm trying to add in a shortcode
Use eftec\bladeone;
$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';
$blade=new bladeone\BladeOne($views,$cache,BladeOne::MODE_AUTO);
echo $blade->run("hello",array("variable1"=>"value1"));
I'm getting an error in the Use line
Parse error: syntax error, unexpected 'Use' (T_USE)
Try:
<?php $i = 0; ?>
<h1>test switch where $i={!! $i !!}</h1>
@switch($i)
@case(0)
Zero case...
@break
@case(1)
First case...
@break
@case(2)
Second case...
@break
@default
Default case...
@endswitch
It will end up in empty output because 0 == 'RANDOM##VALUE!!!AAAA!!!###AAAA##AA'
is true
in php.
Also your tests are broken in linux filesystems, in particular
echo $blade->run("test.switch"
, ["name" => "hello"
, 'records' => $records
, 'i' => 44
]);
will not find a template, because directory named Test
, not test
.
I need some tiny component-like views which only contain a few lines of code but are fed with dynamic data from a database - in concrete I need two nested divs with a button that has a dynamic data-attribute. I don't want to create a file for this few lines of code because things will get messy quite quick as the amount of tiny code snippets grow. I know that I could use @include or @component in order to load a view from a file but that's just not what I want. Would it be possible to enable the @yield method to pass data to a section in order to do something like this:
@section('generic_popup_button_markup')
<div class="generic_action_buttons">
<button class="btn btn-mutateable generic-show-location-on-map-btn" data-marker="{{$popup_id}}">Show location on map</button>
<button class="btn btn-mutateable">Get in touch for this Object</button>
</div>
@endsection
<!-- some more code and stuff -->
@yield('test', ['popup_id' => $some_db_md5_record])
these buttons/markup is used in several different places and I don't like the thought to do changes to their markup in all sports as soon as it changes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.