So, I'm making a CMS at the mo, and using the modular extensions HMVC CI 2.0. It's lovely. I'm wondering the correct method for keeping my assets (js, css, img) related to a module within the module directory.
The problem being, how do I link to these assets? Let's say I'm using a template engine and passing the js files to load for a specific page:
$js[] = 'assets/js/my_js.js';
I suppose I'm asking this all wrong, but is there an easy way to link using the current module's directory?
Thanks in advance.
There's nothing currently built in to CI or HMVC for this.
I prefer not to reference files that are allowed direct access, like images/js/css, from within the application directory. Mainly because:
I don't want anyone to know what the guts of my app look like. By referencing files from directly within a module, you expose your application's directory structure.
I would never do this if I weren't using HMVC
You must now allow direct access to (certain) directories within the application via .htaccess. For security reasons, I prefer to simply disallow the entire thing.
I understand the desire to be as modular as possible, but to me it's not worth this hassle. I prefer to keep a separate directory in a public folder called "modules" (duplicating my application/modules structure), that has nothing but "assets" (css, js, images...).
I'd offer some code but I have no clue how you are adding js/css to your views - it's probably much different than the way I do it. It would be easy enough to write a function to detect the current module, controller, or method and change the asset folder automatically, but this may interfere with other shared assets. I'd suggest writing an entirely separate function for loading assets from modules.
Related
I'm pretty new to laravel and so far I'm liking it. Due to some situations where I forgot to include my new js or css files into my layout, Im looking for a way to link all files from those folders.
Im totally willing to create this myself, but I'm not sure what is the best way to do this. So far I have registered some serviceproviders, like viewcomposers and helpers. I was thinking I can make another viewcomposer which collects the folders I want, and link it to the desired layout.
But I don't want to create unnecessary functions (which might already exist). I'm hoping you guys can give me some insight in what's possible in laravel, good/bad practice, useful classes to use etc.
I wouldn't do this.
I would use Elixir (depending on which version of Laravel you are using) to compile and version my assets. This will mean that you only need to include the references to one file CSS file and one JS file in your view.
https://laravel.com/docs/5.3/elixir
You then just need to maintain your gulpfile.
Versioning your assets also means that you never need to CTRL+F5 to refresh them.
I have installed CodeSleeve asset-pipeline to manage and minify assets for my project. As I understood, all the scripts and stylesheets are controlled from manifest files located at: app/assets/stylesheets/application.css and app/assets/javascripts/application.js
That is all great, but what if I want to load different assets for different page? For example admin side of the application.
This situation is also mentioned in asset-pipeline documentation and recommended to use separate manifest files.
For example, if your application is silo'ed into admin section and user section then it probably makes sense to have a separate manifest file for each section.
Sounds great, but question remains. How?
Here is a similar question about asset-pipeline on Rails 3.1 and a somewhat complicated solution for such a obvious need, as is the need to include different assets in different sections of the application.
I still tried to make sense of that solution, but this is about Rails, so I still have no idea where are the manfiest files added in Laravel version?
I must admit I first went much longer and complex path, hacking the config array with Laravel Event listener. Got it working though until I turned on production environment, which broke my admin section styles. Now after all the hair-pulling came back to asset-pipeline documentation and found the very simple solution which had been right in front of my eyes the whole time: All you have to do is add parameter to include tag, like this:
<?= javascript_include_tag('admin/application') ?>
This will point to folder assets/admin and look for application.js from that folder. Resulting html markup will be:
<script src="assets/admin/application.js" data-foo="bar"></script>
Same thing with stylesheets.
If i've built a web app using code igniter, what's the proper way to deploy it? Should my install only include my files, or do I also package all the codeigniter code with it?
I'm just entering into the world of open source so I'm not so sure what protocol is.
Thanks.
This is a good question and I've seen it done both ways. There's definitely reasons Not to include the CI files. Like any potential in the future license changes. And it seems like with the projects that are shared by more experienced developers that is how they do it.
Because if you are sharing your project for other CI developers, then the reality is they will not use the copy of CI you include - they will fold your files into their version of CI. So including JUST the files needed for your app - actually makes much it easier. Its certainly what I would prefer. Just keep the standard application folder structure: config controllers models etc. but only include the folders that you have files for. And make it clear what version of CI you have tested it on. If you can say it will work on the release version (not the beta) then people on PHP 5.2 will know they can use it.
Of course you need to include all the CodeIgniter files, or else how would it run?
Most people tend to rename the application and system files and place them outside of the web root for security reasons. "After moving them, open your main index.php file and set the $system_folder and $application_folder variables, preferably with a full path, e.g. '/www/MyUser/system'".
Examples given are from Kohana 3, but the question is not limited to the framework.
I've always put my assets in a file structure like this
application
- classes
- views
assets
- css
- js
- swf
- images
-- layout
-- content
system
- classes
I've started reading a few forums where people always mention their assets files are placed in the views folder. This makes a lot of sense to me as these files are tied to the views quite closely (being included by markup). Plus, it will unclutter the docroot.
What is the preferred location of a site's assets? If I do place them under an views/assets folder, where should the actual template files go... under a separate folder like views/templates ?
For ASP.NET MVC
The project template gives you the folders ~\Content and ~\Scripts with the latter containing JQuery.
Why not follow this model, adding additional folders below these if they would otherwise get too many items.
I would stick to the project template unless there is a very good reason to override it (and also override the logic to find views and controllers).
I tend to place mine in the web root (wherever that's defined by the framework) so that I can reference /assets/img/myimage.jpg (or an analogous CSS/JS file, etc.). As Richard suggests, though, I do this because I'm sticking to the framework convention. I'm not familiar with Kohana, but the frameworks I've used extensively all place assets in the web root by convention.
Is there a recommended location to store static resources (images, css, js, etc) in a DotNetNuke 5.x installation?
There are /images and /js folders as well as a /Resources folder that contains resources. There appears to be some overlap as MicrosoftAjax.js is in multiple locations (but might be different versions?). I also could put resources in a /DesktopModule/ModuleX location.
Does anyone know if there is a difference in using any of these folders?
I kinda like the idea of all static resources being under a common folder (/Resources) so I could set caching rule headers, permissions, etc on them in one place.
Has anyone used a separate image server to serve DotNetNuke static content?
Pros and Cons of a separate image server (e.g. images.mydomain.com)?
If you own the entire DNN installation, then it can certainly make sense to consolidate all of your resources into one place (whether its the Resources folder used by DNN, or a different folder that DNN doesn't know about). If you're developing a module that will be installed onto a site that you don't totally own, then the considerate thing to do is to constrain your resources within the DesktopModules folder for your module.
Some things to consider with regards to DNN folders:
If you have content under a module's folder, uninstalling that module will give you the option to delete that content. This can help you keep things clean and organized, or it can make it can be dangerous if you have multiple module definitions sharing the same files... (Even more dangerous can be the uninstall SQL scripts; make sure you don't accidentally uninstall a module which has an uninstall script attached)
You can use the DNN file manager to upload/delete/rename files within the Portals directory, so it may make sense to put files there if site administrators should have control of them
Putting content outside of the module's folder will make it slightly more difficult to link to (especially if it's on a portal specific folder, i.e. you have to ask the PortalSettings object for the path every time)
It's uncommon to keep resources outside of the module's folder, and so may cause confusion if you bring an experienced DNN developer into the project
For skins and containers, you can use their own folders under the Portals directory. As bdukes said, this way site administrators can control them within DNN.
For modules, I have used the module's folder and module.css for defaults that can be overridden by skin or container css. This works because skin and container css are loaded after the module.css.