Closed maduranga001 closed 6 years ago
Here is the specific NBS tokens: http://www.nbrightproject.org/Documentation/TagTokens
But your probably going to need to use the info.GetProperty() class method for getting from the xml data.
Here is a link to show you how to get the XML format.
http://www.nbrightproject.org/Documentation/Integrator-guide/Data-Format
Also please try asking question on the forum.
Thank you for the reply @leedavi .
I already tried your above options through the same links.
I used this on "/DesktopModules/NBright/NBrightBuy/Themes/ClassicRazor/Default/productfields.cshtml" file. `@if (@info.GetXmlProperty("genxml/textbox/customfield") != "") {
}`
I am getting this error on the Add Product page.
RazorEngine.Templating.TemplateCompilationException: Errors while compiling a Template. Please try the following to solve the situation: If the problem is about missing/invalid references or multiple defines either try to load the missing references manually (in the compiling appdomain!) or Specify your references manually by providing your own IReferenceResolver implementation. See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details. Currently all references have to be available as files! If you get 'class' does not contain a definition for 'member': try another modelType (for example 'null' to make the model dynamic). NOTE: You CANNOT use typeof(dynamic) to make the model dynamic! Or try to use static instead of anonymous/dynamic types. More details about the error: - error: (28, 6) The name 'info' does not exist in the current context - error: (33, 25) The name 'info' does not exist in the current context Temporary files of the compilation can be found in (please delete the folder): C:\Windows\TEMP\RazorEngine_rzjcinfy.nei The template we tried to compile is: ------------- START ----------- @if (@info.GetXmlProperty("genxml/lang/genxml/textbox/customfield") != "") { My custom field: @info.GetXmlProperty("genxml/lang/genxml/textbox/customfield") } ------------- END ----------- The generated source code is: ------------- START ----------- //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace CompiledRazorTemplates.Dynamic { using System; using System.Collections.Generic; using System.Linq; [RazorEngine.Compilation.HasDynamicModelAttribute()] public class RazorEngine_04553b858846475194aff089b9f1ec83 : NBrightBuy.render.NBrightBuyRazorTokens { public RazorEngine_04553b858846475194aff089b9f1ec83() { } public override void Execute() { WriteLiteral("\r\n\r\n"); if (@info.GetXmlProperty("genxml/lang/genxml/textbox/customfield") != "") { WriteLiteral(" My custom field: "); Write(info.GetXmlProperty("genxml/lang/genxml/textbox/customfield")); WriteLiteral("
Please, advise where is the problem?
That razor looks wrong, try and remove the @ on the @info.
But this problem looks released to the included references, make sure you have the basic ones.
@inherits NBrightBuy.render.NBrightBuyRazorTokens<NBrightRazor> @using System.Linq @using NBrightDNN @using Nevoweb.DNN.NBrightBuy.Components;
This is what I am getting now. I attached the file I modified. Please, can you tell me if I have used it well? Please, Still I did not get the exact way to do this.
RazorEngine.Templating.TemplateCompilationException: Errors while compiling a Template. Please try the following to solve the situation: If the problem is about missing/invalid references or multiple defines either try to load the missing references manually (in the compiling appdomain!) or Specify your references manually by providing your own IReferenceResolver implementation. See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details. Currently all references have to be available as files! If you get 'class' does not contain a definition for 'member': try another modelType (for example 'null' to make the model dynamic). NOTE: You CANNOT use typeof(dynamic) to make the model dynamic! Or try to use static instead of anonymous/dynamic types. More details about the error: - error: (20, 105) Type expected Temporary files of the compilation can be found in (please delete the folder): C:\Windows\TEMP\RazorEngine_45ytxrku.a5m The template we tried to compile is: ------------- START ----------- @inherits NBrightBuy.render.NBrightBuyRazorTokens<> @using System.Linq @using NBrightDNN @using Nevoweb.DNN.NBrightBuy.Components; @if (info.GetXmlProperty("genxml/lang/genxml/textbox/customfield") != "") { My custom field: info.GetXmlProperty("genxml/lang/genxml/textbox/customfield") } ------------- END ----------- The generated source code is: ------------- START ----------- //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace CompiledRazorTemplates.Dynamic { using System; using System.Collections.Generic; using System.Linq; using NBrightDNN; using Nevoweb.DNN.NBrightBuy.Components; [RazorEngine.Compilation.HasDynamicModelAttribute()] public class RazorEngine_e2b39316e3c041db9cb8a760a99a4456 : NBrightBuy.render.NBrightBuyRazorTokens<> { public
OK, the productfield template is for editing... not displsying, tdiusplsying is done in the normal template.
this should go in produectfirlds ...
@TextBox(info, "genxml/textbox/txttest2", "class='form-control' maxlength='250'")
I think your putting the display section in the edit section.
productfields.zip It is same and still, I am getting the same error.
RazorEngine.Templating.TemplateCompilationException: Errors while compiling a Template. Please try the following to solve the situation: If the problem is about missing/invalid references or multiple defines either try to load the missing references manually (in the compiling appdomain!) or Specify your references manually by providing your own IReferenceResolver implementation. See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details. Currently all references have to be available as files! If you get 'class' does not contain a definition for 'member': try another modelType (for example 'null' to make the model dynamic). NOTE: You CANNOT use typeof(dynamic) to make the model dynamic! Or try to use static instead of anonymous/dynamic types. More details about the error: - error: (20, 105) Type expected Temporary files of the compilation can be found in (please delete the folder): C:\Windows\TEMP\RazorEngine_hs5azcfy.gzw The template we tried to compile is: ------------- START ----------- @inherits NBrightBuy.render.NBrightBuyRazorTokens<> @using System.Linq @using NBrightDNN @using Nevoweb.DNN.NBrightBuy.Components; @if (@TextBox(info, "genxml/textbox/txttest2", "class='form-control' maxlength='250'") != "") { My custom field: @TextBox(info, "genxml/textbox/txttest2", "class='form-control' maxlength='250'") } ------------- END ----------- The generated source code is: ------------- START ----------- //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace CompiledRazorTemplates.Dynamic { using System; using System.Collections.Generic; using System.Linq; using NBrightDNN; using Nevoweb.DNN.NBrightBuy.Components; [RazorEngine.Compilation.HasDynamicModelAttribute()] public class RazorEngine_3794e960928141caa4a5c572c7c2449a : NBrightBuy.render.NBrightBuyRazorTokens<> { public RazorEngine_3794e960928141caa4a5c572c7c2449a() { } public override void Execute() { WriteLiteral("\r\n\r\n"); WriteLiteral("\r\n"); if (@TextBox(info, "genxml/textbox/txttest2", "class='form-control' maxlength='250'") != "") { WriteLiteral("
I did all the instructions. But I am missing something. I really appreciate if you can help me with this. All these things need to do in the 'productfields.cshtml' file. Am I correct? I have sent you this file before. I am attaching it here too. Please, can you do that change in this file and send me here? I think it would be helpful to others too. I think if you could add a one custom field to this file and comment it for a reference, that would be ideal for any other developer.
I need the text field called "Mega Points".
Please, help.
Ys sorry, I understand now what the problem is. You need to define the info data class. It's not very well explained in the documentation., I've improved it. Here is what you need.
@inherits NBrightBuy.render.NBrightBuyRazorTokens
@{ var info = (NBrightInfo)Model.List.First(); }
Thank you for replying.
Ok. I've added your above code to "/DesktopModules/NBright/NBrightBuy/Themes/ClassicRazor/Default/productfields.cshtml" file.
I am not getting any errors now. But I can not see any custom fields in the 'Articles' for product add/edit page. (mysite.com/Admin-Panel/Products-Back-Office/ctrl/products)
What else should I do now? To be honest, It is difficult to me to do only through the document. I really appreciate if you guide us.
Yes, you need to change the display template to display the custom fields. It won't pickup unknown fields without you altering the template to display them.
Change NBS_ProductDisplayDetail.cshtml
and add your new custom fields.
@info.GetXmlProperty("genxml/textbox/txttest2")
Ok. Great. But I think you have mistaken the file name. It is Admin_ProductDetail.cshtml . Am I correct? I added the following code.
@LangFlag(info.Lang) @TextBox(info, "genxml/lang/genxml/textbox/txtMegaPoints", "class='form-control' maxlength='250'") And now the field is in my Add new product view. So please help me with these Three questions too. 1) This value is not saving to the database. I added a value and just saved it. All other fields are filling with the previous values. But not for this. Any issue? How can I save this and use o display it back? 2) Where can I add a resource key? On which file and what is the code? MegaPoint text to apply in the Label. To use for this. @LangFlag(info.Lang) 3) How can I display the New field value in the product list view? What is the code for the token? I really appreciate if you can give me the complete code line(s) for this. Thank you very much for your guidance. This will be a good reference for new developers to add a new field.The resx is the "Generacl.ascx.resx" file, but it'll be overwritten, best to create a new one.
The Productfields.cshtml should save Ok, it does on my system.
It is the "NBS_ProductDisplayDetail.cshtml" template, your trying to display on the product detail (or list, pick list template)
you just need to add
@info.GetXmlProperty("genxml/lang/genxml/textbox/txtMegaPoints")
Ok. Thank you for the reply. I could sort out the Resource value and also I think I could add the token to the list view. But it is a blank. The reason should be the custom field value is saving a blank. Still, it is not saving my value. It is blank and not populating back the value I entered like other default fields.
`@inherits NBrightBuy.render.NBrightBuyRazorTokens
@{ var info = (NBrightInfo)Model.List.First(); }
My custom field: @textbox(info, "genxml/textbox/txtMegaPoints", "class='form-control' maxlength='250'")`
on productfields.cshtml page.
I revalidated a few times and restarted the site too.
Why is this data not saving and not displaying back? I used the code as it is (mentioned the code in the previous comment).
Please, advise. Where have I missed?
Check the DataBase XML data to make sure. It saves on mine and I can't think of any reason it shouldn't.
You got to understand this is open source, you should look at the code and debug the situation.
make the xpath lower case, check for JS error. Check the database record in NBrightBuy table.
I changed the control name - 'txtMegaPoints' to 'txtmegapoints'. Then it is working. I do not know why. But the control name is working only when it is in lowercase only.
Thank you for helping me, David. I am giving a step by step summary here how to add a new product field here. So it will be helpful for others in the future. These are the steps with example code.
1) I need to add 'txtmegapoints' text field as a new product field. Control name must be in lowercase. a) Open -'/DesktopModules/NBright/NBrightBuy/Themes/config/default/productfields.cshtml' File. b) You can place the same file in '/Portals/0/Themes/config/default/productfields.cshtml' to avoid the replacing the file with upgrading. (Use your appropriate portal ID folder)
This is the code.
`@inherits NBrightBuy.render.NBrightBuyRazorTokens
@{ var info = (NBrightInfo)Model.List.First(); }
My custom field: @textbox(info, "genxml/textbox/txtmegapoints", "class='form-control' maxlength='250'")`
NOTE : Do not forget to Validate Store after each and every code changes. Backoffice > Admin > Tools and Click on "Validate Store" Button. Then Refresh the page and see if your changes are there.
2) Open '/DesktopModules/NBright/NBrightBuy/Themes/config/default/Admin_ProductDetail.cshtml' file to apply the control to the Add/Product Product view.
This is the code. You should find the proper place to add to your template. `
I am using NBS_3.6.7_Install on DNN 9.1.1 version with Classic Razor Theme.
I need to add the followings to the product list view in the Products list view.
Summary Manufacturer Code Extra
How can I add these tokens to the template and display? Please advise. What would be the token code and how and where to modify?
Appreciate your support.