Loop over files in Twig - twig

I am using Bolt CMS and want to have a table including all files of a specific directory on the server. How can this be achieved using a Twig template?

I have found that the following call works. The argument is a path in the files directory.
{% set files = app.filesystem.browse('SomeDirectory')[0] %}

This is not twig's task. This is something the controller layer should be responsible.
Get the list of files in your controller (though I'd probably create a model-layer class for this), and pass the list to your view, where it only needs to display it.

Related

Use Twitter Bootstrap LESS files with NPM, in Apostrophe CMS

What is considered best practice if I want to use compile Bootstrap from LESS files in my Apostrophe project?
Is it better to install Bootstrap via NPM, or should I manually download Bootstrap and place the files in lib/modules/apostrophe-assets/?
I have reviewed the documentation that I am aware of to try and figure this out. I am not finding any documentation about including CSS and JS assets which are located outside of the lib folder.
I'm the lead developer of Apostrophe at P'unk Avenue.
You can put those files in lib/modules/apostrophe-assets/public/css (and subdirectories thereof, if desired) and include the one that imports all of the others in your configuration for apostrophe-assets, exactly as described in the tutorials:
Pushing assets to the browser
Or you can import it from a LESS file of your own that also imports your custom site-specific styles. That's really up to you.
Of course there is also nothing stopping you from adding assets directly to your outerLayout.html via link and script tags but if you want to take advantage of Apostrophe's minification process, follow the tutorial.
To be clear, any and all templates in Apostrophe can be overridden for your particular project WITHOUT modifying the node_modules/apostrophe folder in any way.
If a template exists at this path:
node_modules/apostrophe/lib/module/MODULE-NAME/views/TEMPLATE-NAME.html
Then just copy it here in your project:
lib/module/MODULE-NAME/views/TEMPLATE-NAME.html
And your version will be rendered instead.
You can use the Nunjucks extends keyword to extend templates that you invent yourself. You can also use cross-module syntax to extend templates that are in a different module:
{# Finds it in the apostrophe-templates module, your version first, #}
{# node_modules if that doesn't exist #}
{% extends "apostrophe-templates:layout.html" %}
Hope this clears things up a little better!

More simple inclusion in EJS, avoiding nested file context

So kind of building off of Node.js - EJS - including a partial
I’ve got a series of EJS templates, all organized in a series of folder. Many include the same header.ejs file. For each include, I need to have an include along the lines of <% include ../partials/footers/footer %>. Because some files are nested deeper/in more folders than others, each has to be set manually.
Is there a solution to avoid this? For example, is there a parameter to set all includes to be based from the root of the views directory (in which all .ejs files are placed)?

Must include files in nanoc always be in the layouts folder?

We would like to use server side includes (SSI) in the content of our nanoc site. This would allow us to chunk shared information and include it in multiple pages. It would also allow us to only maintain one source file of this shared information.
I figured out how to add an SSI (partial) in nanoc. As you know in nanoc we have the following root level folders, among others:
/content/
/layouts/
According to the instructions I found (https://nanoc.ws/doc/items-and-layouts/#partials), it seems the “partials” or include files need to be in the /layouts/ folder (outside of the /content/ folder).
For example:
The following code is used to insert the include file /layouts/partials/shared/test.html
<%= render 'partials/shared/test/' %>
In other words, the code assumes the include file will be placed in the layouts folder. Do you know of a way to change the default path for SSIs to /content/? This way we won’t mix content with layouts?
Thank you in advance.
Partials by default are in the layouts/ directory, and are used through the rendering helper using the #render helper method.
However, you can also put content to include (“partials”) in the content/ directory, too, although the approach then is different.
For example, create content/partials/foo.txt:
I am included!
Make sure the partial files are not routed nor compiled, so edit Rules and ensure these rules are executed first:
compile '/partials/*' do
write nil
end
Now in any item or layout you can include this partial:
<%= #items['/partials/foo.*'].compiled_content %>
This assumes the includer item/layout is filtered using ERB, but you could also use Haml or so.
You can let the compile rule do some processing, e.g. perform Markdown filtering, and then the HTML output from the filter will be included.

Is it possible to use virtual paths / subfolders registering scripts in Orchard Themes?

I'm trying to build a new Orchard theme, and to keep things structures I'd like to put script includes in separate folders (this particular script include needs quite a bit of files so to put all of them in the root of the scripts folder doesn't seem so great).
Basicly I can't wrap my head around this:
Script.Require("~/ThemesFolderEtc/Scripts/libs/shadowbox/shadowbox.js");
it seems only possible to do something like this:
Script.Require("shadowbox.js");
Does anyone have any pointers on what virtual path to use, and if it's supported to use virtual paths?
I believe Script.Require is key/value dictionary of registered scripts. Try Script.Include("path"). This is what I do with my css file. I point it to a file on in public dropbox folder which makes changing the css super easy and no ftp!

When generating SubSonic DAL, is it possible to have .gen.cs in the generated filenames?

When generating my DAL files with SubSonic, I'd like the names of the files to be .gen.cs. The main reason for this is that the files are partial classes, and I would like to add some additional implementation details into another source file for the table called .cs. This is somewhat the standard pattern for generated source files , and I'm wondering if its possible with SubSonic? I'm using SubSonic 2.2.
I thought you might be able to do this by using a set of custom templates, but the CS_ClassTemplate.aspx (or VB_ClassTemplate.aspx) doesn't control the file name of the class.
I don't think this is possible.
As an alternative, you can do what I do. I have a "generated" directory, such as \database\generated and then I put my partial classes at \database\custom. As long as the namespaces of the files in the two different directories match (like .database or whatever), then it works fine. By using two different directories, it's easier to find your custom files without looking at the generated ones.

Resources