FuelPHP - Use Asset it Twig template - fuelphp

I'm starting using FuelPHP.
Currently, I'm able to display a wonderful page without any images or style. I'm happy. :P
But I would like to insert my CSS and some images. So, I've tried to used the «Asset» function, as described in the documentation (http://fuelphp.com/docs/classes/asset/config.html).
But when I insert something like «<script src="{{ Asset::js('bootstrap.min.js') }}"></script>» in my template, I got this error:
Twig_Error_Syntax [ Error ]:
Unexpected token "punctuation" of value ":" ("end of print statement" expected) in "index.twig" at line 223
What's wrong? How can I use Asset:: ?
Thanks a lot
(And sorry if it's a noob's question :/)

Aha! I've found how it works.
It's not Asset::css but asset_css and it generates all the link tag.
so {{ asset_css('style.css')|raw }} is perfect.

Related

Error: Unable to find an element with the role "alert" (react-testing-library example)

I'm using the stock codesandbox example from react-testing-library and I've added two files, Login.jsx and __tests__/Login.js . These files are copied directly from the react-testing-library examples on the main readme.md.
However, when the test suites run, I get an error:
Error: Unable to find an element with the role "alert
When I debug this, the html output does not appear to have any role attributes in any of the divs. What am I doing wrong?
Codesandbox: https://codesandbox.io/s/react-testing-library-examples-dh1e7
Probably it's too late. But anyway.
Your components does not set success field it relies later on:
{state.success ? (
<div role="alert">Congrats! You're signed in!</div>
) : null}
Probably it should be state.resolved

View raw markdown of GitHub comment

How can I view the Markdown of a comment in a GitHub issue? For example, I would like to see the Markdown that makes up this comment:
https://github.com/jashkenas/backbone/issues/3857#issue-116738665
Simply replace username, reponame and issue number in the following url:
https://api.github.com/repos/USERNAME/REPONAME/issues/NUMBER/comments
Here's an example
First, the first post is the actual issue itself, not accessible but the GitHub issue API:
https://api.github.com/repos/jashkenas/backbone/issues/3857/comments
That list only 3 comments, since the first post is not a comment.
The issue itself has a formatted body:
https://api.github.com/repos/jashkenas/backbone/issues/3857
That returns:
"body": "In Safari , pass a path using unicode string to `navigate` method like this\r\n\r\n```js\r\nBackbone.history.navigate('/city/北京',{trigger:true});\r\n```\r\nThe hash is incorrect. It output\r\n\r\n```js\r\nlocation.hash\r\n//> #/city/%17%AC\r\n```\r\n\r\nI tracked the code, it caused by `_updateHash` method.\r\n\r\nThe call stack created by `History.prototype.navigate` method like this\r\n\r\n* navigate\r\n - decodeFragment\r\n - _updateHash\r\n\r\nThe fragment passed to `_updateHash`, was decoded by `decodeFragment`, so the hash was incorrect。\r\n\r\nI also searched the commit history, the `decodeFragment` added in \"1.2.0\"\r\n\r\nPS: My english is not good, although I am trying to improve\r\n\r\n",
That is not exactly mardown:
In Safari , pass a path using unicode string to `navigate` method like this
```js\r\nBackbone.history.navigate('/city/北京',{trigger:true});
```\r\nThe hash is incorrect. It output
```js\r\nlocation.hash
//> #/city/%17%AC
```
I tracked the code, it caused by `_updateHash` method.
The call stack created by `History.prototype.navigate` method like this
* navigate
- decodeFragment
- _updateHash
The fragment passed to `_updateHash`, was decoded by `decodeFragment`, so the hash was incorrect。
I also searched the commit history, the `decodeFragment` added in \"1.2.0\"
PS: My english is not good, although I am trying to improve
The second comment in this issue has two images, so those fancy effects are no markdow:
https://cloud.githubusercontent.com/assets/516562/11164567/62f9ddf6-8b2f-11e5-8aa8-631c1aa84422.gif
[https://jsfiddle.net/leexiaosi/uyp3o6ek/](https://jsfiddle.net/leexiaosi/uyp3o6ek/)
**notice!!!** : please open in safari.
### the record of safari
![safari](https://cloud.githubusercontent.com/assets/516562/11164567/62f9ddf6-8b2f-11e5-8aa8-631c1aa84422.gif)
### the record of chrome
![chrome](https://cloud.githubusercontent.com/assets/516562/11164583/c66d1b82-8b2f-11e5-9d88-ecba16ae6167.gif)
It's probably late. But I could somewhat do it this way (at least in firefox).
I am assuming your intention is to copy the formatting of the comment.
This is not an exact solution, but since GitHub supports HTML tags in comments, this will work just fine.
Right click somewhere at the top of the comment you want to copy.
Inspect element
In the Inspect Element box, you will find a line that's a few lines above the highlighted line which has this code:
<td class="d-block comment-body markdown-body js-comment-body">
Right click on the line having the above code
Select Copy>Inner HTML
Now you can either paste this in a comment box, preview it and you'll be able to see the same formatting, OR use an online HTML to MD converter.
You can see the raw markdown by using "Quote reply" (found after clicking three dots at top right of a comment.
Here's the beginning of the comment you asked for:
In Safari , pass a path using unicode string to navigate method like this
Backbone.history.navigate('/city/北京',{trigger:true});
The hash is incorrect. It output
location.hash
//> #/city/%17%AC
...

Gravity-forms Better Pre-submission Confirmation not working

I am using gravity forms on my wordpress site and using the code from
http://gravitywiz.com/better-pre-submission-confirmation/
to get the pre-submission confirmation page. I have done as instructed but there are no additional merge tags displaying in the HTML field apart from the standard ones.
I am getting the following errors on setting wp_debug mode to true.
Strict Standards: Declaration of GFCategoryWalker::start_el() should be compatible with Walker::start_el(&$output, $object, $depth = 0, $args = Array, $current_object_id = 0)
Non-static method GWPreviewConfirmation::init() should not be called statically
I don't really understand these errors and not able to find any documentation about it in relation to gravity forms.
Any help will be appreciated.
Thanks.
Well, the second of these issues looks like something to do with the PHP version. This post about a similar issue on get_base_path() suggests just adding the static keyword before function init:
https://wordpress.org/support/topic/debug-error-message
Edit: see here for explanation of the declaration should be compatible...
Strict Standards: Declaration of ' ' should be compatible with ' '

Ways to call Blocks within Magento: createBlock vs Layout xml file

Context: I'm trying to include Adminhtml blocks in the frontend of the site to replace some of the user account blocks. The first thing I'm trying to do is simply display the block on the correct page. I can replace the entire page by setting the Body of the response inside the controller, but I'm having a hard time including the block in the layout xml file and then calling it within the template.
This block's default template is adminhtml/default/default/widget/grid.phtml. So I have placed widget/grid.phtml and widget/grid/ folder (needed by widget/grid.phtml) inside of the frontend theme.
I'm using community edition v1.3.2.2
Why would I be able to create an adminhtml/sales_order_grid from Mage_Sales_OrderController using createBlock:
$this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/sales_order_grid')->toHtml());
But not from a frontend layout, using a declaration
<sales_order_history>
<reference name="content">
<block type="adminhtml/sales_order_grid" name="orders_widget"/>
</reference>
</sales_order_history>
within app/design/frontend/default/default/layout/sales.xml
The latter produces an error without a stack trace:
Fatal error: Call to a member function toHtml() on a non-object in app/code/core/Mage/Core/Model/Layout.php on line 526
That line is the function getOutput() that Alan refers to below. The data in callback[0] is blank. As far as I can tell, it's null. When output to a log, it's blank. get_class(callback[0]) returns nothing discernable as well.
As far as I can tell, no blocks are rendered. There is nothing shown in the browser except the error message. In the log, the only output from the getOutput() method within app/code/core/Mage/Core/Model/Layout.php is the one where it breaks - no block name in callback[0].
However, I do know that _prepareCollection on the sales_order_grid block is being called.
Update: It turns out that I can get the block to render by adding it to the layout file. The call that throws the error is in app/code/core/Mage/Sales/controllers/OrderController.php in public function historyAction(). The call to $this->renderLayout() is what causes the problem. Evidently, I can't have both the grid block and the history template rendered in the same action. I'm not sure why though.
Thanks for any guidance!
More details about the other customizations you've done to get yourself to this point might help people troubleshoot your problem. When I tried your "create the block programmatically" code I got the following error.
Warning: include(/path/to/magento1point4.dev/app/design/frontend/base/default/template/widget/grid.phtml) [function.include]: failed to open stream: No such file or directory in /path/to/magento1point4.dev/app/code/core/Mage/Core/Block/Template.php on line 189
I added a simple phtml template to the above location and was able to insert the block via a layout file succfully after that
<reference name="content">
<block type="adminhtml/sales_order_grid" name="orders_widget"/>
</reference>
So I suspect something you've done along the way already is tripping things up.
Also, a Magento version would help things. Line 526 of the current version of community edition is a comment.
All that said my best guess is things are failing in the getOutput method of the Layout class. I'd add some logging to the function on your dev server to see what Magento is trying to do/instantiate when it bails on you.
public function getOutput()
{
$out = '';
if (!empty($this->_output)) {
foreach ($this->_output as $callback) {
Mage:Log('Trying to get the block ' . $callback[0] . ' and call its ' . $callback[1] . 'method');
$out .= $this->getBlock($callback[0])->$callback[1]();
}
}
return $out;
}

How can I write a Template.pm filter to generate PNG output from LaTeX source code?

I am looking for a way of generating PNG images of equations from LATEX source code embedded in templates. For example, given:
[% FILTER latex_display ]
\begin{eqnarray*}
\max && U(x,y) \\
\mathrm{s.t.} && p_x x + p_y y \leq I \\
&& x \geq 0, y \geq 0
\end{eqnarray*}
[% END %]
I would like to get the output:
<div class="latex display"><img src="equation.png" width="x" height="y"></div>
which should ultimately display as:
I am using ttree to generate documents offline. I know about Template::Plugin::Latex but that is geared towards producing actual documents out of LATEX templates.
Any suggestions?
Update:
I appreciate the suggestions (and I have voted them up). However, they are no quite what I need. I would really appreciate a few pointers towards getting started with a Plugin or Filter for Template Toolkit.
Wikipedia does something similar to what you want. They use a program called texcv. Then you also have MathJAX which is more aimed at dynamic math rendering in web-pages.
texcv is according to the linked page written in OCaml however since the rest of Mediawiki is written in PHP I don't think you should have any problem with repurposing the program to use with Perl.
you should take a look at jsMath, MathML, or mathjax
I would really appreciate a few pointers towards getting started with a Plugin or Filter for Template Toolkit
These docs on Template Toolkit site should provide all necessary info to setup a plugin or filter:
Plugin provider module
Base class for plugin filters
Once you have your LATEX to PNG conversion sorted then you probably need to save it as a file using redirect. Example from POD:
[% PROCESS my/png/generator
FILTER redirect("images/logo.png", binmode=1) %]
Hope that helps.
/I3az/