Adding a custom template

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 năm cách đây
Hi,

I want to add a custom template for displaying a specific category of products.  However, when I build my template control, VS can not find the type and throws error.  Example:

1. I copied ProductsInLines1.ascx and pasted into same folder.  I changed name to ProductsInLines3.ascx
2. I changed the inheritance at the top of the control to Templates_Categories_ProductsInLines3
3. I changed the code behind namespace to match the above.
4. I entered a new template in the admin panel and pointed it at my new control in the templates folder.

What appears to be happening is that the templates are looking to inherit NopSolutions.NopCommerce.Web.Templates.Categories.NameOfYourControl.  Where is this located?  Is this in one of the dll files?  I can't find where to register this in web.config, as nothing of the type is anywhere to be found.

The code for a custom template is pretty straightforward but I don't know how to implement it.

Any ideas?  Thanks.

joe
14 năm cách đây
i think you need to re-compile the project - this is what my programmer told me, compile the project if you made any changes on .cs file or added new files to project.
14 năm cách đây
Thanks for responding, but that is where my error pops up.

When I rebuild, VS doesn't have any reference to my new template.  Somewhere I should be able to add my control template to NopSolutions.NopCommerce.Web.Templates.Categories.NameOfMyNewTemplate.  Other asp.net sites use underscores(_) instead of dots(.) for mapping the location of files.  I have tried both ways. i.e.

1. NopSolutions.NopCommerce.Web.Templates.Categories.ProductsInLines3 AND
2. Templates_Categories_ProductsInLines3

Both throw errors on rebuilding.  I am not the sharpest tool in the shed, but what am I missing?

joe
14 năm cách đây
Hi,
VS doesn't need a reference to your new template - as long as it is part of the project.
But you have to take care that the corresponding code-behind file to your new control exists
and and is named in the right way.
Copy an renaming an existing control, doesn't necessary lead to a new class with this name.
In this case the class name inside the file, will not be changed automatically to the new file
name if another class with the old name still exists in the project ... this is caused by the
refactoring engine to avoid strange side effects.
You can check this by searching the old class name in new files - nothing should be found.
14 năm cách đây
I understand what you are describing, but my problem is still the same.

My understanding of asp.net controls is that in the control declaration they must inherit a control file somewhere (usually themselves).  So file xyz.ascx located in folder abc would be declared in the control declaration as abc_xyz.ascx or in the naming format of nopCommerce, abc.xyz.ascx.

The code behind references the namespace or abc and then a class of xyz is used.  I suppose the class name that was copied from the original file could still be used.

The problem I get is that when the page is parsed, the parsing engine does not know what abc.xyz or abc_xyz is.  If I build a custom control and place it in the modules folder and declare it's inheritance as modules_123.ascx I have no problem and the control is parsed correctly.

Templates appear to just be controls, but something else is happening. Where is this breakdown occurring?

Thanks for helping.

joe
14 năm cách đây
Figured it out!

I was looking for an assembly or xml file where this control needed to be registered.  Not needed.  The solution was amazingly simple.  

Here is the link that explained it.

In a nutshell, VS uses 'codebehind' for web applications and 'codefile' for web sites.  Since nopCommerce is probably compiled as a web application, if you open it for editing as a website you must use 'codefile'.  Everything works fine, the site builds, parses, and works as expected.

If there are any gotchas or concerns about editing nopCommerce as a website in VS I would love to hear them.

Hope this helps anyone else who has this problem.

joe
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.