How can i call phtml file into cms page used widget? - magento-1.9

I have a phtml file mw/news/slider.phtml so how can I call it into cms page by used widget?

Maybe you should to create the widget with 'CMS Static block' type and assign the static block with {{block type="[block_type]" template="[template_file]"}} directive to it? But I think that it would be better to use the {{block type="[block_type]" template="[template_file]"}} directive directly in the CMS Page?

Related

How do I add a Dynamic Link in Custom HTML Widget?

I am developing a website on my local environment and want to add "Custom HTML" widgets to my website footer and megamenu. I want to be able to add images and links through these custom HTML widgets.
The problem is that I have to hardcode the absolute URL path (e.g. http://localhost/client_projects/hom/site/wp-content/uploads/2018/03/image.png)
When the time arrives to go live I will have to root out and swap all the URLs in my widgets. Not good.
So how do I dynamically link to pages and images in Custom HTML widgets?
You can add dynamic tokens/variables using add_filter.
Add the following to functions.php:
add_filter('widget_text', function($text) {
$upload_dir_array = wp_upload_dir();
$text = str_replace('{{uploads_dir}}', $upload_dir_array['baseurl'], $text);
return $text;
});
Now in your Custom HTML widget, write your URLs as {{uploads_dir}/2018/03/image.png.

Failing to load html file dynamically and parsing all angularjs directives in html file

So I have a website set up and I wish to dynamically load other .html files into a div. Each .html file contains some content but 1 .html file contains its own angularjs directives.
I was using ng-bind-html along with $scope.content = $sce.trustAsHtml(data); but I have discovered that this prints out the html raw (does not process any angular directives).
I've tried to use the various solutions on stack overflow but none have worked for me.
Website: http://algorithmictrading.azurewebsites.net/
App.js: http://algorithmictrading.azurewebsites.net/js/app.js
Example of .html pages being loaded:
http://algorithmictrading.azurewebsites.net/includes/home.html
http://algorithmictrading.azurewebsites.net/includes/about_us.html
.html page that contains angular directives:
http://algorithmictrading.azurewebsites.net/includes/download.html
As you can see, if you navigate to the website and click on the 'download' tab, the content is loaded but the angular in the drop down menu is not handled. The test button I added should also produce an alert box.
Right now, the code is based off this thread:
call function inside $sce.trustAsHtml() string in Angular js
Thanks!
I found that angular was stripping out the directives from html strings if I didn't pass them through the $sce.trustAsHtml method before passing them into the template:
$sce.trustAsHtml('<a href="/some-link" directive-example>link to add</a>');
This combined with a watch/compile on the element's content you're inserting html into seems to do the trick:
scope.$watch(getStringValue, function() {
$compile(element, null, -9999)(scope);
});
Take a look at this example: http://plnkr.co/edit/VyZmQVnRqfIkdrYgBA1R?p=preview.
Had the same problem this week and the best way I found to make it works was creating a custom directive called "BindComponent".
Change the ng-bind-html directive to a custom directive, and inside the link method you put this:
element.html(markupModel);
$compile(element.contents())(scope);
The markupModel can be a string with html code or you can use $templateCache($templateCache docs) to get the code from a .html file.

web2py controller for layout.html

I'm building a web application using web2py, and have currently implemented search on some of the view/ pages by creating a function in the appropriate controller and then using {{=form}} to render it in my HTML page like this...
<h3>Search</h3>
{{=form}}
{{if results:}}
<h3>Results</h3>
{{for result in results:}}
{{=A(result.title)}}
{{pass}}
Rather than repeat this functionality in multiple pages, I would like to have a search field in my layout.html file, which can then be used across all over views. However, there is no controller for layout.html. Is it possible to use a method in another controller in the layout.html page, or is there another way to link a controller to layout.html that I am missing?
Thanks.

Include plain HTML page inside a Play Framework view template

Is there a way to include a plain html page inside a Play Framework's view template? I have a scenario wherein there is a common view template and in the body of the template, I would like to include certain static html pages. I know that I can include other templates inside a certain template, but I'm not sure if I could include a plain html page?
One option is to just make your static HTML a template, eg, create myStaticPage.scala.html:
<h1>Static page</h1>
<p>This page is static, though it is still a template.</p>
Then your view template, myView.scala.html:
#(staticPage: Html)
<html>
<head>...</head>
<body>#staticPage</body>
</html>
And then in your action that renders the template:
def renderMyStaticPage = Action {
Ok(views.html.myView(views.html.myStaticPage())
}
You just need to make sure that your HTML page escapes any # symbols with ##.
On the other hand, if which HTML page that's being included is more dynamic, then simply load the HTML from the file/database/classloader/whereever it's coming from, eg:
def renderMyStaticPage = Action {
val staticPage: String = // code to load static page here
Ok(views.html.myView(Html(staticPage))
}
You could.
Just put something like that in your routes file:
GET /file controllers.Assets.at(path="/public", file="html/file.html")
Here is a duplicated post: Route to static file in Play! 2.0

Using angular .tpl.html files to build a static .html file

I'm not sure if I'm going about this the right way, however this is what I need to do. I have common .tpl.html files that I want to use both for an angular template and a template to generate a static .html file. What I want is a system (grunt-related) that will take the junk in .tpl.html and insert it in a outer .html file and create a static .html file.
For example, say I have:
stuff.tpl.html
<div> I want this stuff in my overall template </div>
stuff2.tpl.html
<div> I want this stuff in my overall template to create another html</div>
outer.html
<head>
stuff
</head>
<body>
{{insert}}
</body>
where I can make stuff.html (or stuff2.html) by inserting stuff.tpl.html (or stuff2.tpl.html) into outer.html.
I know how to do the angular side, just not the static side.
If I'm not mistaken you need to concatenate multiple static files in to a one single file.
You can use grunt-contrib-concat to do the job. See the below link grunt-contrib-concat
If you need to implement the template with angularJs, you can use grunt-html2js which will convert your static html to angular template. Then you can use grunt-contrib-concat to concat all the angular template and create one js which you can add to your index.html subequently.
Hope this might help you.