Silva Silva · How to get the id from model

How to get the id from model

Last modification: 14.11.2007, Marc Petitmermet


Sometimes one needs to know the id based on the model information; e.g. the id of the enclosing Silva Document in a Silva Code Source.



request = context.REQUEST
model   = request.model
title   = model.get_title()
obj_id  = model.get_content().getId()

Page Template

<tal:define="model  context/REQUEST/model;
             title  model/get_title;       
             obj_id python:model.get_content().getId()">

Explanation [1]

model.getId() returns the id of the version. model.get_content() retrieves the nearest content object (e.g. Silva Document) which is the version's parent. In cases where you're not always sure what your context is, you should use this method since that works for Versioned Content and Versions alike.

[1] by Benno Luthiger and Eric Casteleijn