In the layout file I have
$bundle=MyAsset::register($this);
but I don't know how to use $bundle->baseUrl in the view.
$bundle->baseUrl works corretly in the layout but if I use it in a view I have a Undefined variable: bundle.
As the view is the the yii\web\View object you can access the assetBundles and their baseUrls with inside the view files:
$this->assetBundles['yourAssetBundleName']->baseUrl;
Just for the sake of completeness, if its needed to access image paths within a bundle, you maybe better put them inside the public_html / webroot folder as they are visible to the web anyhow.
You will need to do
$bundle=MyAsset::register($this);
in the view, as well.
As described in the Issue Tracker, Yii will not replace the AssetBundle registered in the layout.
Related
How to exclude in rendering already existing scripts in DOM in Yii2
What method (render or renderAjax etc.) i have to use to exclude rendering one more (the same) jquery, jquery.ui
I have jquery.js on my page. And i (via ajax) load to my page modal window of registration, that requires jquery.js, and it pulls jquery.js second time.
And in the result my page contains 2 jquery.js library. And somewhere starts ocurring errors. I want to fix it by remoeving enother jquery.js
I'm not sure if you are using AssetBundle class but if not - you should.
There is already defined yii\web\JqueryAsset with jquery.js you can use.
Now you can create AssetBundle with your script that will depend on JqueryAsset (read more about assets dependency in the Guide). No matter how many times this asset is registered JqueryAsset will be registered only once.
You can do the same when adding single js file with registerJsFile() - in options array you can use 'depends' key with the JqueryAsset.
Sorry again. I found solution. Here is it
Currently, I have an html file which has a basic layout of a login page which has an option for new users to sign up if they're not a member.
I have the following line inside of my html :
Join Us!
What I want to have happen is load up a new HTML page which will be a modal (using twitter bootstrap) that will ask the user to input the correct data to create a login/pass combination.
But this isn't working. It keeps doing the following (doesn't do anything) :
http://localhost:3000/register.html
I'm a little confused whether my HTML is wrong or MeteorJS requires some sort of specific way to do something like this.
You can use a relative url: Example: register.html only
If your file is into the same project, you don't need to put him an url absolute.
Put your register.html file in your project's /public directory and you will be able to access it via /register.html. However that page will run outside your Meteor app and won't have any Meteor functionality per se.
The /public folder maps to / and is normally used for images and other client-side assets. It's common to map /public/images to /images for example.
I made a website with Twitter bootstrap and the design is finished in terms of all the HTML and CSS.
Now I need to add functions like making an account and blogging. I decided to use Ruby on Rails to do this, but I have no idea where to put the files and how to connect them.
So far I have figured out that I want to put them in the "views" folder and have it say, for example, "index.html.erb" but I don't know if that goes into another folder in "views" or how any of that works.
I also don't know where to put all the CSS and JavaScript incorporated with bootstrap.
Following Rails conventions, views should go in a dir that mirrors the model name (plural), which also aligns with the controller name. i.e. model = user, views dir = users, controller = users_controller.rb. You should read through at least the first few Rails guides; esp this layout and rendering one:
RE the bootstrap portion of this question, just use the bootstrap-sass gem and follow the instructions for including it in your application.scss and application.js.
Using ASP.NET MVC3 with Razor & C#.
Say I have an application that is set up to run as a normal website through IIS, but now I want to run this application as a sub-application under another website. For example, the sub-application will be stored in a folder called "SubApp" off the root of the website (e.g. www.example.com/SubApp/).
If I reference a URL such as "~/Images/picture.gif" within SubApp's razor mark-up/code-behind, it will resolve to the root of SubApp: www.example.com/SubApp/Images/picture.gif
However, if I reference "/Images/picture.gif" through regular HTML (in SubApp), it will resolve to the root of SubApp's parent website: www.example.com/Images/picture.gif
Is there an easy, reliable way to resolve these HTML URLs to the sub-application's root without rewriting them to use Razor? What's the best way to handle URLs under these circumstances?
If you're dealing with pure HTML pages that will be requested directly by a browser, you should use relative URLs. For example, if you have:
/SubApp
/Images
foo.gif
page.html
You should use:
<img src="foo.gif" />
Inside page.html. You can use "../" to go up directories, etc.
Unfortunately, if you're dealing with a more complicated server-side routing scenario, you're going to need to use some kind of server-side code to handle that.
I want to use custom css/js. I have moved these to the server. But the drupal page starts with a section. how do I add the custom css/js to my drupal site page. I have admin and just need to know what to do to get this included on the page. Please send exact steps as I am totally new to drupal. Thanks
"Custom CSS and JavaScript files" module allows to specify two folders, one for CSS and one for JS where the stylesheets and javascripts files are located respectively.
The module creates two sub-folders under your files folder:
files/customcssjs/css
files/customcssjs/js
Indeed, it's depend on your task, what css and js files should do, and adding these in custom module (drupal_add_js, drupal_add_css) or custom theme (info file, preprocess in template.php or directly in page-XXX.tpl.php and so on).