"According to a chronicle on the Templars’ beginnings, attributed to Ernoul, (...) the first Templars were a group of knights who had dedicated themselves to the Holy Sepulchre after the First Crusade. They realized that the country needed warriors, and criticized themselves for living an idle and comfortable life when they should be working. So they decided, with the permission of the prior of the Sepulchre, to elect a Master who could lead them in battle as necessary. King Baldwin II gave his approval for the scheme, and called the patriarch of ]erusalem, the archbishops and the bishops, and the barons of the country together. After discussion the new Order was approved. King Baldwin gave them land, castles and towns and persuaded the prior of the Sepulchre to release them from their obedience to him. (...)
Although this account was written after 1187, when the Saracens captured Jerusalem, it does give a convincing account of the Order’s beginnings. It combines the suggestions of the earlier accounts: the Order of the Temple was set up on the initiative of the knights themselves, and that these knights were pilgrims who had come to the kingdom of Jerusalem but who had settled in the city, and who saw that the country needed warriors. The new Order was approved both by the king and by the patriarch. In addition, this account would help to explain why writers in the West were sometimes confused about the relationship between the Hospital of St John, set up in the 1060s or 1070s to care for poor sick pilgrims to Jerusalem, the Order of the Temple, and the canons of the Holy Sepulchre, the priests who lived and worked in the Church of the Holy Sepulchre. It also explains why the Hospitallers and the Templars in the Holy Land followed the liturgy of the Holy Sepulchre in their church services, and why the seal of the Master of the Temple bore the image of the dome of the Holy
Sepulchre. According to ‘Ernoul’, all three groups were originally together. The Hospitallers and Templars had begun life as part of the religious community based in the Church of the Holy Sepulchre."
This blog quotes from "The Knights Templar - a brief history of the warrior Order" by Helen Nicholson (2010); illustration Seal of the Master of the Knights Templar showing the dome of the Church of the Holy Sepulchre in Jerusalem, source Wikipedia