-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displaying markdown from a .md file #8
Comments
Hey! If its a file you have and want to render, I would recommend getting the file contents out and sending that to the template as a variable. return view("admin/taskview", ["title" => $p, "file_contents" => file_get_contents($fileName)]); <html><head></head>
<body>
<div>
{{ file_contents | markdown }}
</div>
</body> I believe you could also use the new twig syntax of applying filters to blocks. <html><head></head>
<body>
<div>
{% apply markdown %}
# Some Markdown
This is some simple markdown content.
{{ moreMarkdown }}
{% endapply %}
</div>
</body> If you have multiple variables that are not markdown, but want to create markdown and render it in the final output, the way you are doing things is probably easiest. <html><head></head>
<body>
<div>
{% markdown %}
# {{ title }}
{{ some_paragraph }}
## Sub Heading {{ extra_text }}
{% endmarkdown %}
</div>
</body> Was this working for you? |
Hi! I was thinking something along the lines of <html><head></head>
<body>
<div>
{% include_markdown(markdown_filename) %}
</div>
</body> Below was working for me, but it has a few downsides: <html><head></head>
<body>
<div>
{% markdown %}
# {{ title }}
{{ some_paragraph }}
## Sub Heading {{ extra_text }}
{% endmarkdown %}
</div>
</body>
Below involves reading the file contents midway through the code pipeline. It seems to me that Laravel avoids doing things this way, and instead, delaying it all the way til rendering. I'm not sure, but I think the aim is to keep memory usage low. Nonetheless, it seems to be my only option if there are no better ways. return view("admin/taskview", ["title" => $p, "file_contents" => file_get_contents($fileName)]); Thank you. |
I believe twig has a <html><head></head>
<body>
<div>
{{ source(filename) | markdown }}
</div>
</body> |
The syntax works fine. Twig can't find the |
I'm able to get the above syntax to work in tests but I haven't tried it in an actual project. Perhaps the markdown file must be declared as a twig template some how. |
I'm about to trace deep into twig's code |
Let me know what you find out. I can create tests from that to make sure it's working in the future with future releases and so on. If not, I could potentially add a new function like |
Hey man, it works, however, I have to pass in the absolute path; relative paths did not work. Now I wonder if there are any security issues since twig files could be made editable for power users. LOL |
Hi, It was working until I have this markdown
It outputs this HTML
|
Hi,
I have twig view and some markdown files which contain twig variables, i.e.
{{ filename }}
. What is the best (laravel) way to include the contents of the MD to be parsed as markdown in the twig view?e.g.
currently, my twig file is like:
and my PHP code is like
I would like to separate the markdown and twig so that the twig is reusable. Thank you.
The text was updated successfully, but these errors were encountered: