我使用Umbraco 7.13.1
我已经创建了一个自定义数据类型,并且运行良好。但现在我需要将数据呈现到页面的模板中。
app_pluggin
js文件
angular.module('umbraco').controller('IBD_HeaderController', function ($scope) {
$scope.model.value.Tag = $scope.model.value.Tag || "default value";
$scope.model.value.HeadingText = $scope.model.value.HeadingText || "default value";
console.log($scope.model);
$scope.SetTag = function () {
$scope.model.value.Tag = $scope.value.Tag
};
});
html文件
<div class="IBD_CMS" ng-controller="IBD_HeaderController">
<div>
<input class="headingTextBox" type="text" ng-model="model.value.HeadingText" ng-change="SetHeading()">
</div>
<div class="HeadingTag">
<label class="TagOption">
<input type="radio" name="HeadingTag" value="h1" ng-model="model.value.Tag" ng-click="SetTag()">
<span>H1</span>
</label>
<label class="TagOption">
<input type="radio" name="HeadingTag" value="h2" ng-model="model.value.Tag" ng-click="SetTag()">
<span>H2</span>
</label>
<label class="TagOption">
<input type="radio" name="HeadingTag" value="h3" ng-model="model.value.Tag" ng-click="SetTag()">
<span>H3</span>
</label>
<label class="TagOption">
<input type="radio" name="HeadingTag" value="h4" ng-model="model.value.Tag" ng-click="SetTag()">
<span>H4</span>
</label>
<label class="TagOption">
<input type="radio" name="HeadingTag" value="h5" ng-model="model.value.Tag" ng-click="SetTag()">
<span>H5</span>
</label>
<label class="TagOption">
<input type="radio" name="HeadingTag" value="h6" ng-model="model.value.Tag" ng-click="SetTag()">
<span>H6</span>
</label>
</div>
</div>
表现
{
propertyEditors:[
{
alias: "IBD.Heading",
name: "Intelligence By Design Heading",
editor: {
view: "~/App_Plugins/IBD.Heading/IBD.Heading.View.html",
valueType: "JSON"
}
}
],
javascript: [
"~/App_Plugins/IBD.Heading/IBD.Heading.js"
],
css: [
"~/App_Plugins/IBD.Heading/style.css"
]
}
我可以在内容编辑器中设置信息并将其全部存储起来。
我的问题是如何将其作为2个单独的值重新输入cshtml文件
即Model.content.ComponentName.HeadingText Model.content.ComponentName.Tag
我现在有
pageHeading = Model.Content.GetPropertyValue<string>("cartName");
这回来了
{“标签”:“H3”,“HEADINGTEXT”:“我的购物车”}
我要这个
pageHeading =我的购物车页面HeadingTag = h3
你应该创建自己的C#类来代表你的对象
public class TagClass {
public string TAG{get;set;}
public string HEADINGTEXT{get;set;}
}
然后你可以实现自己的属性值转换器https://our.umbraco.com/documentation/extending/property-editors/value-converters https://skrift.io/articles/archive/custom-property-value-converters/
或者只是反序列化它:
var tagClass = JsonConvert.DeserializeObject<YourClass>(Model.Content.GetPropertyValue<string>("cartName"));
谢谢eyecream昨晚解决了它创建了一个模型和控制器然后调用函数,该函数将字符串反序列化为模型以返回到cshtml文件。你的看起来容易多了,但是我想在插件中添加更多的变量,所以我认为我的长期工作也是如此。