Is there a way to tell Razor (DNN's View Engine) to use a different Views Folder for a MVC Module? - razor

I'm trying to use multiple folders for my views in a custom MVC module for DNN.
The goal is to choose a theme in the module settings and then depending on the setting use a different view folder (i.e. use different cshtml files for the actions).
Is there a way to tell razor that it should look up other locations first?
(Can I use the ViewLocationExpander in DNN for my module?)
Thanks!

I understand that you want to have some kind of App settings and have MVC use the setting to select the View for you. I believe that is possible, but there is a simpler, lower-tech way to do it if using #RenderPage() or #RenderPartial() make sense for what you are trying to do.
So imagine you start in _index.cshtml
You could either have your files in folders and construct the path (imagine the setting is something like Path = "live" or "staging"):
#RenderPage(myApp.Settings.Path + "/_List-Filtered.cshtml",
title = "No filters",
index = myIndex
)
Or directly modify the filename instead
#{
string myViewname = "Person";
}
#RenderPage("_List__" + myViewName + "--Filtered.cshtml")

Related

Dnn Razor Script Localization

I know how to localize regular DNN modules but I'm not sure where to begin with Razor Scripts hosted in the DNN Razor Host Module.
I keep my localization resx files in a separate assembly so I thought the easiest thing would be to the resources from the Assembly using the ResourceManager but this doesn't seem to tie in well with Dnn's localization framework, since the resources won't be editable in Dnn.
If at all possible I'd like to keep the resource files embedded but I would understand if that was not possible.
Either way, how do I access these resources in a Razor Script file in Dnn?
you can use this apporoach, but I'm not sure if it is what you looking for...
#using DotNetNuke.Services.Localization
#{
var localResourceFile = "/DesktopModules/RazorModules/RazorHost/Scripts/App_LocalResources/SharedResources.ascx." + Dnn.Portal.CultureCode + ".resx";
var text = Localization.GetString("pepamaca.Text", localResourceFile);
}
<div>#text</div>

PhpStorm - extend PHP Class template

I'm trying PhpStorm. I like the File Templates functionality and I'd like to use it in some more specific cases.
I'd like to extend to PHP Class template to create a new template that I'll be using for a specific type of classes. If I just duplicate the template, it doesn't really work as I'd expect. For example, while when I use PHP Class, the namespace is already compiled, this does not happen with my new template.
Is it possible to create another template so that it works as PHP Class?
Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?
Is it possible to create another template so that it works as PHP Class?
Unfortunately not; at least not in current versions (2016.2).
When you are using New | PHP Class you see special dialog box that works with 3 templates (depends on what you will be creating: Class, Interface or Trait). This dialog uses file templates with predefined (default) names only and you can customize them as you wish .. but all other file templates for .php files will be just ordinary File Templates without those extras.
Based on your requirements you might be interested in https://youtrack.jetbrains.com/issue/WI-21711 ticket -- watch it (star/vote/comment) to get notified on any progress.
Please note that file templates could be project-specific (different template content for each project) -- this might be enough in some (rather simple) cases.
Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?
Unfortunately not -- no sorting/subfolders is available (although you may have project-specific file templates).
Right now I may only suggest to use some common prefix in template name and build your sorting order around this idea.
Other than that -- https://youtrack.jetbrains.com/issue/IDEA-75239 + https://youtrack.jetbrains.com/issue/IDEABKL-3599 -- watch these tickets (star/vote/comment) to get notified on any progress.

yii2: where do my project's own html, css, js, and php-include files go?

Choices:
create an asset bundle (nicely explained by Ivo Renkema at How do I manage assets in Yii2?). this is what I need if I want to package my code for other use. alas, should I also do this for my own php include library functions? Or should I still stick them into the same php location as my other php files? In any case, if I want to go this route, presumably I would then customize the AppAsset class, included in the template, as explained in http://www.yiiframework.com/doc-2.0/guide-structure-assets.html .
stick my files directly into $basePath/web, where $basePath is typically something like /var/www/myapp/ (i.e., as $basePath/html/mine.html [and refer to it simply as href='/html/mine.html'], $basePath/css/mine.css , $basePath/js/mine.js, and $basePath/php/mine.php [and refer to it as $basePath= \Yii::getAlias('#webroot'); require_once('$basepath/php/mine.php') ])?
stick my local files where my php view code sits. the advantage is that the files are close to where I will use them. the disadvantage is that I may litter the view directories not only with php files, but also with my non-asset assets, even though they will be used only by these (my) php files.
it's a beginner's question for the google cache reference. it's about best practice when getting started. I can guess the answer, but we wouldn't want a novice to disseminate bad info.
If you need your CSS and JS files only in one view or one Controller you have 2 choices:
1- Create a asset bundle Here other guide if you need it.
2- Use registerJsFile() from View Class
You can acces from controller using:
Yii::$app->view->registerJsFile('js.path');
(Same with CSS files but using registerCssFile())
With the PHPfiles I always try to convert the code to yii's MVC. If you have a entire library try to add it as a component. Here a usefull guide

How to run sql query to return data from different joomla components

I am trying to customize the source files of a Joomla component.
Before the Joomla MVC model introduced, I was able to run SQL queries in a component, Kunena 1.0 to select data from another component. e.g Sobi2.
However, after Kunena 1.5 [MVC model] was introduced, I do not know how / where to add the SQL query to select data from Sobi2.
I believe I need to add some codes in the files of the /models/ or /func/ folder. But can someone provide more detailed assistance on how I can achieve this?
The data interaction is done by the model, you will find Kunena models in the model folder.
Querying the SOBI2 databse is the same as before, MVC wouldn't actually affect how you do this.
To get your head around MVC, have a look at:
http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
For examples of how to query the database in your model, look at:
http://docs.joomla.org/How_to_use_the_database_classes_in_your_script
In simple terms, the Controller directs to the appropriate view (view.html.php), this view then interacts with the model, and then directs to a template file (normally located in the view/tmpl folder.
Hope this helps.

fluent nhibernate + how to create sql schema

I have a question about how to render the sql schema with fluent nhibernate.
I have searched alot and used a couple of things but i dont know how to render it. I´m only building the ground of my website, the core. And now i want to create the database from my mappings. How do i do that? Is it with testrunning or what?
If i build the solution i don´t get any sql file i have also tried export it to hbm files to use schema tool export but dont get it to work.
have tried
Fluent NHibernate (1.2.0.712) export mappings to HBM not working / not respecting conventions
and
https://stackoverflow.com/questions/5244257/build-schema-with-fluent-nhibernate
and alot other links.
What do i have to do to get the sql file? every site give almost the same code but they don´t tell how to render it. How to execute the process to retrieve the file..
can anyone tell me? i can build it by my self but i want to try this function!
best regards
You can create the database using the SchemaExport.Create method:
// this NHibernate tool takes a configuration (with mapping info)
// and exports a database schema from it
new SchemaExport(config)
.Create(true, true);
If you want to see the generated SQL, you can use the ShowSql method, but this is not required to create the database.
_sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard
.UsingFile(SqliteDatabaseFullPath())
// Display generated SQL in Output window
.ShowSql()
)
...
It's been my experience with NHibernate that it's almost always best to start with a working example, so I suggest you get the FirstAutomappedProject sample project that is part of the FNH source. This will give you all the pieces you need.
Probably easiest to download the zip file (button on the upper left) which includes all the FNH source code, and look in the "src" folder for the examples.