I have a component with comment name. this component has a view file with test.php name.
I would like to render another view file in test.php. How I can do this?
file map:
component/
|
comment.php
view/
|_
test.php
another.php
You can simply do it this way to have multiple views.
$this->render('view1', array('model' => $model));
// then, inside the view you can render a subview like this:
$this->renderPartial('view2', array('model' => $model));
Hope this helps you.
Related
Using Net.Core 7 I have a few View Components which are located in:
/Pages/Components/Component1/Default.cshtml
/Pages/Components/Component2/Default.cshtml
...
I want to place all views in Components folder and use the Component's name:
/Pages/Components/Component1.cshtml
/Pages/Components/Component2.cshtml
...
I was able to change the name from Default to Component1 using:
public IViewComponentResult Invoke() {
return View("Component1");
}
Can this be accomplish with a global configuration?
What about placing all in Components folder and not using one folder per component?
You can use RazorViewEngineOptions e.g.
builder.Services.AddControllersWithViews();
builder.Services.Configure<RazorViewEngineOptions>(o =>
{
o.ViewLocationFormats.Clear(); //Or just add another
o.ViewLocationFormats.Add
("/Components/{0}" + RazorViewEngine.ViewExtension);
});
Be careful about o.ViewLocationFormats.Clear() it may make the other mvc controllers not work
I'm working on a tab view app with VueJS and Framework7.
I have f7-links that each open a f7-view element (so not actual tab elements). Inside one of these tabs, I would want to do nested navigation using f7-link-item with the link parameter. I am using the same component to render this page but I need to pass data to each link to identify which link was clicked (and to know which content to render).
I am trying to get this data with
created() {
console.log(this.$f7router.currentRoute);
}
But the weird thing is, this shows the previous route (the component that the link was clicked on, not the current component). If I do just
created() {
console.log(this.$f7router);
}
THEN the currentRoute shows the correct one.
For reference, my ordinary tab links are like this:
<f7-toolbar tabbar labels bottom id="toolbar">
<f7-link tab-link="#view-menu" tab-link-active text="Menu"></f7-link>
</f7-toolbar>
<f7-view id="view-menu" main tab tab-active url="/menu/"></f7-view>
And my nested routing links are like this:
<f7-list-item link="/product/0" class="product-link">
Coffee
</f7-list-item>
Routing itself works great, I just don't understand how to pass the prop I want and why the currentRoute parameter isn't working.
Thank you very much!
Try using this.$f7route instead of this.$f7router.currentRoute.
$route or $f7route
(object)
Current route. Contains object with route query, hash, params, path and url
https://framework7.io/docs/router-component.html#component-context
Context:
I have a section of a view that I want to update on a regular interval via JS.
What I have done so far:
Using the information given in: Viewcomponent alternative for ajax refresh
created a view component that encapsulates the region that I want to refresh
attempted to create a custom route to a view component as follows
options.Conventions.AddPageRoute("/Components/ViewComponent/default", "FriendlyRouteAlias");
use the following script to attempt to load the (updated) view component and inject the value into a div:
<script>
var container = $(".DataToUpdate");
var refreshComponent = function () {
$.get("Route/to/view/component", function (data) { container.html(data); });
};
$(function () { window.setInterval(refreshComponent, 1000); });
</script>
Is it even possible to load a View Component this way or should I be looking at another way of accomplishing this?
As the commenters suggested, I was able to get it working by using an MVC controller action to return the view component directly. I will add that I used an MVC controller rather than an API controller because I was dealing with a view rather than data. (see Difference between ApiController and Controller in ASP.NET MVC)
Hi I have a situation where I need to compose only a view and not a viewModel for this I have set this composition statement in my html:
<!-- ko compose: { view : content }-->
<!--/ko-->
Content represent an observable from my viewmodel.
The problem is that it seems the framework is also trying to download the viewmodel which does not exist and has no reason to exist.
Does anyon no how to stop Durandal from looking for the viewModel?
I have tryed setting the model : null but it did not work
You can't stop Durandal looking for the view model if you're using the compose binding, but there are a number of things you can do to prevent loading a new model:
Point Durandal to a dummy object to use as the model (e.g. create a singleton dummyModel.js);
Use a "dumb" object (for example an array) for your model:
<!-- ko compose: { view : content, model: [] }--><!--/ko-->
Use the current model, and turn off activation (to prevent activate being called on the model twice):
<!-- ko compose: { view : content, model: $data, activate: false }--><!--/ko-->
Basically, Durandal doesn't care what you give it as a model, as long as it has something to use. Note that it will still bind whatever model you specify to your view though!
try this
<div>
<div data-bind="compose:'views/content.html'"></div>
</div>
I am not sure if this will answer your question but I did come across a similar situation where I wanted to load views of my application which had no viewmodels. I created a module which given the view would load the view for me. All I had to was overwrite the getView function of my custom viewmodel which loaded my views.
//viewLoader --> it's job is to load the views which do not have any viewmodels
define(['plugins/router], function(router){
return {
getView: function() {
return "views/"+router.activeInstruction().config.file +".html";
}
}
}
In Jquery theres a function
$(document).ready(function (){..}
Is there such a thing in Sencha Touch 2?
I'm aware of
Ext.Setup({ onReady: function () {...} })
However I can only call Ext.Setup once. If I have multiple views how would I take care of this? I would like a function to load when a view is loaded. Do I have to this via a controller? Can I use a snippet of code injected into the index.html (The platform is built on node and requires this)?
Inside of your controller that requires the view just add an init: function() { //do something }, extjs will take care of the rest... usually if your trying to call a function that requires the view to be loaded, then add the 'painted' listener to your view and it will be called when the view is rendered