I need to access a file in the static folder of Yesod, which gets uploaded there at runtime, so it does not have an identifier.
Is there any way to construct a static route to such file?
You can use the StaticRoute constructor directly, along the lines of:
StaticRoute ["somefile.txt"] []
Related
Based on a video with Codeigniter4, I created the Modules folder on the ROOTPATH and the Controllers, Views..etc folders in the Modules folder. It works fine, but when I want to call my view file inside the module
<?php
namespace Modules\Giris\Controllers;
use App\Controllers\BaseController;
class IndexController extends BaseController
{
public function index(){
return view('Modules\Giris\Views\index');
}
}
I need to specify a very long path like How can I make it just like view('index') and call the file from the Views folder in that module if I write it in a module? I don't want to write "Modules\Login\Views" in short is this possible?
Thanks in advance for all the kind replies.
Because view requires a string you couldn't provide a namespaced reference as you might think you should. Furthermore the code adds a .php extension and the "view path" (defined in your config\paths file) as part of its process (see system/View/View.php and render()). Therefore without modifying Codeigniter (which could be done but would affect all your code) the easiest way is to simply declare a public property or constant and make reference to that instead. Also helps if you need to change the path at any point.
I.e. protected $path = 'Modules\Giris\Views\' and then view($this->path.'index'); is probably the easiest way.
Using Nunjucks with Node
Trying to figure out a graceful solution to the following problem. With a directory tree sorda like this:
app_dir
--app.js
--public
----stylesheets
------mystyles.css
--views
----page.html
----templates
------page_template.html
Have static files like CSS inside my public directory
app.use(express.static(path.join(__dirname, 'public')));
Have the root directory of Nunjucks configured as views
nunjucks.configure('views', {
autoescape: true,
express : app,
watch: true
});
When I am referencing a css file from within page_template.html, nunjucks (I think) automagically creates a relative path based on the route and overrides the static behavior.
For example, when I use /stylesheets/mystyles.css path on page_template.html but call the file that extends it using
/:publication/:page path, the rendered html is /:publication/:page/stylesheets/mystyle.css
I can always write a quick hack that creates relative paths to CSS and other resources based on the route but that doesn't feel like a particularly graceful solution :( Any help much appreciated.
When I am referencing a css file from within page_template.html, nunjucks (I think) automagically creates a relative path based on the route and overrides the static behavior.
I think it's mistake. Nunjucks don't generate any path.
In template from any folder (view, view/templates, etc) you must specify filename considering that public dir is root, e.g.
/stylesheets/mystyles.css for %app%/public/stylesheets/mystyles.css.
I use subfolders in view for grouping templates, e.g. /macros (stored macros), /tools (stored additional pages for my app). Also you can use it to router, e.g. /user/view.html, user/add.html...
I"m trying to instantiate a UIMAp (the reason i need this is currenly i'm having an error thats occuring and i think its because i need to instantiate it). I've read online about how to do it but my UI maps are named the same as my cs files that are created. and i cant seem to see if i'm actually instantiating it correctly since its just a class. I have reference in the file
which is
using Microsoft.VisualStudio.TestTools.UITest.Common.UIMap;
But i dont think i'm accessing it or am i and just dont know
I tried this code HomePage MyNewUIMap = new HomePage();
but i don't believe its correct here is my folder structure
For example my folder and file structure is
--> Home (folder)
---->HomePage.uiTest(UIfile)
------->HomePage.cs (file)
----------->HomePage.Designer.cs (file)
I normally keep a utility class that does nothing but instantiate my maps. Then, I can just call MyUtility.HomePage.objectOnHomePage when I need to interact with that object, and I don't need to instantiate each map on each test class. However, the actual method for instantiating my maps is done below:
public HomePage myHomePageMap
{
get
{
if (_homePage == null)
_homePage = new HomePage();
return _homePage;
}
}
private HomePage _homePage;
I do it this way to make sure that, if I've already instantiated the map, I don't create a duplicate instance of it.
In a shakespearean template, I need to get the route to a static dir. How can I achieve that?
#{StaticR images_myimage_png} <-- works
#{StaticR images} <-- does not work
#{StaticR images_} <-- does not work either
In order to do that, you'll need to use the StaticRoute constructor directly. The identifier generation only generates identifiers for files, not directories, since that's normally what people want (as #zudov explains). You should be able to do something like:
#{StaticR $ StaticRoute ["images"] []}
I am setting-up the server response of a query to couchbase and want to use handlerbars to render the response data.
I understand that the best practice is to have my helper functions into a separate file and not be embedded in a script tag in my html file.
My question is what is the best practice or technique to pass the data from the server response to my hanldbars helper file to then be manipulated?
I am using hapijs on the server and jQuery on the client.
Well I might be wrong, but following this example I found, it seems like you export the helper file like you would any other module with the module.exports
http://codyrushing.com/using-handlebars-helpers-on-both-client-and-server/
According to the API documentation for hapi the helper file must export a single method with the signature `function(context).
Helpers are functions used within templates to perform transformations
and other data manipulations using the template context or other
inputs. Each '.js' file in the helpers directory is loaded and the
file name is used as the helper name. The files must export a single
method with the signature function(context) and return a string.
Sub-folders are not supported and are ignored. Defaults to no helpers
support (empty path). Note that jade does not support loading helpers
this way.
https://github.com/hapijs/hapi/blob/master/docs/Reference.md#route-options