What are the differences between getRawSomething and getSomething methods on Archetypes contents (eg. ATNewsItem)?
For exemple, what is the difference between getRawImage and getImage? Or getRawRelatedItems and getRelatedItems? etc.
What are the differences between getRawSomething and getSomething methods on Archetypes contents (eg. ATNewsItem)?
For exemple, what is the difference between getRawImage and getImage? Or getRawRelatedItems and getRelatedItems? etc.
getRaw*为您提供存储在对象上的直接、未处理的原始数据。允许这些get*方法根据需要以某种方式转换该数据。
例如,TextField字段在使用 时会将文本转换为安全的 HTML get,但getRaw()会为您提供未转换的数据,无论是 markdown、restructedtext 还是未处理的 HTML。
来自开发者文档:
Archetypes 有两种访问方法:
- normal,
getSomething(),过滤输出;- raw,即所谓的编辑访问器,
getRawSomething()它不过滤输出。
如果要编辑字段的当前内容,请使用getRaw*,在呈现内容时,请使用get*。
具体来说,相关项目存储在一个引用字段中,该getRaw()方法返回对象 UID,该get()方法返回对象,首先为您解析 UID。
图像字段,如文件字段,将在使用时将数据包装在关联的对象类型(OFS.Image对于图像字段)中,.get()但返回底层存储所获得的任何内容.getRaw()。通常该对象已经被包装了。